Changeset 168c007


Ignore:
Timestamp:
Mar 21, 2017, 12:50:27 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
da6d4566, f5392c1
Parents:
94a8123 (diff), e04b636 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Files:
29 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/concurrency/thePlan.md

    r94a8123 r168c007  
    88_Phase 2_ : Minimum Viable Product
    99done - Monitor type and enter/leave mutex member routines
    10 Monitors as a language feature (not calling enter/leave by hand)
     10done - Multi monitors calls,
     11done - Monitors as a language feature (not calling enter/leave by hand)
    1112Internal scheduling
    1213
    1314_Phase 3_ : Kernel features
     15Preemption
    1416Detach thread
    1517Cluster migration
    16 Preemption
    1718
    1819_Phase 4_ : Monitor features
    19 Multi monitors calls,
    2020External scheduling
    2121
  • src/Concurrency/Keywords.cc

    r94a8123 r168c007  
    1717#include "Concurrency/Keywords.h"
    1818
     19#include "SymTab/AddVisit.h"
    1920#include "SynTree/Declaration.h"
    2021#include "SynTree/Expression.h"
     
    2930        namespace {
    3031                const std::list<Label> noLabels;
     32                const std::list< Attribute * > noAttributes;
    3133                Type::StorageClasses noStorage;
    3234                Type::Qualifiers noQualifiers;
     
    6365        //                                           void main( MyCoroutine * this );
    6466        //
    65         class CoroutineKeyword final : public Mutator {
     67        class CoroutineKeyword final : public Visitor {
     68            template< typename Visitor >
     69            friend void SymTab::acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
    6670          public:
    6771
    68                 static void implement( std::list< Declaration * > & translationUnit ) {}
     72                using Visitor::visit;
     73                virtual void visit( StructDecl * decl ) override final;
     74
     75                void handle( StructDecl * );
     76                Declaration * addField( StructDecl * );
     77                void addRoutines( StructDecl *, Declaration * );
     78
     79                static void implement( std::list< Declaration * > & translationUnit ) {
     80                        CoroutineKeyword impl;
     81                        SymTab::acceptAndAdd( translationUnit, impl );
     82                }
     83
     84          private:
     85                std::list< Declaration * > declsToAdd, declsToAddAfter;
     86                StructDecl* coroutine_decl = nullptr;
    6987        };
    7088
     
    97115
    98116                using Visitor::visit;
    99                 virtual void visit( FunctionDecl *functionDecl ) override final;
    100                 virtual void visit(   StructDecl *functionDecl ) override final;
     117                virtual void visit( FunctionDecl * decl ) override final;
     118                virtual void visit(   StructDecl * decl ) override final;
    101119
    102120                std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );
     
    111129          private:
    112130                StructDecl* monitor_decl = nullptr;
     131                StructDecl* guard_decl = nullptr;
    113132        };
    114133
     
    124143
    125144        //=============================================================================================
     145        // Coroutine keyword implementation
     146        //=============================================================================================
     147        void CoroutineKeyword::visit(StructDecl * decl) {
     148                if( decl->get_name() == "coroutine_desc" ) {
     149                        assert( !coroutine_decl );
     150                        coroutine_decl = decl;
     151                }
     152                else if ( decl->is_coroutine() ) {
     153                        handle( decl );
     154                }
     155
     156        }
     157
     158        void CoroutineKeyword::handle( StructDecl * decl ) {
     159                if( ! decl->has_body() ) return;
     160
     161                if( !coroutine_decl ) throw SemanticError( "coroutine keyword requires coroutines to be in scope, add #include <coroutine>", decl );
     162
     163                Declaration * field = addField( decl );
     164                addRoutines( decl, field );
     165        }
     166
     167        Declaration * CoroutineKeyword::addField( StructDecl * decl ) {
     168                Declaration * cor = new ObjectDecl(
     169                        "__cor",
     170                        noStorage,
     171                        LinkageSpec::Cforall,
     172                        nullptr,
     173                        new StructInstType(
     174                                noQualifiers,
     175                                coroutine_decl
     176                        ),
     177                        nullptr
     178                );
     179
     180                decl->get_members().push_back( cor );
     181
     182                return cor;
     183        }
     184
     185        void CoroutineKeyword::addRoutines( StructDecl * decl, Declaration * field ) {
     186                FunctionType * type = new FunctionType( noQualifiers, false );
     187                type->get_parameters().push_back(
     188                        new ObjectDecl(
     189                                "this",
     190                                noStorage,
     191                                LinkageSpec::Cforall,
     192                                nullptr,
     193                                new PointerType(
     194                                        noQualifiers,
     195                                        new StructInstType(
     196                                                noQualifiers,
     197                                                decl
     198                                        )
     199                                ),
     200                                nullptr
     201                        )
     202                );
     203                type->get_returnVals().push_back(
     204                        new ObjectDecl(
     205                                "ret",
     206                                noStorage,
     207                                LinkageSpec::Cforall,
     208                                nullptr,
     209                                new PointerType(
     210                                        noQualifiers,
     211                                        new StructInstType(
     212                                                noQualifiers,
     213                                                coroutine_decl
     214                                        )
     215                                ),
     216                                nullptr
     217                        )
     218                );
     219
     220                CompoundStmt * statement = new CompoundStmt( noLabels );
     221                statement->push_back(
     222                        new ReturnStmt(
     223                                noLabels,
     224                                new AddressExpr(
     225                                        new UntypedMemberExpr(
     226                                                new NameExpr( "__cor" ),
     227                                                new UntypedExpr(
     228                                                        new NameExpr( "*?" ),
     229                                                        { new NameExpr( "this" ) }
     230                                                )
     231                                        )
     232                                )
     233                        )
     234                );
     235
     236                FunctionDecl * get_decl = new FunctionDecl(
     237                        "get_coroutine",
     238                        Type::Static,
     239                        LinkageSpec::Cforall,
     240                        type,
     241                        statement,
     242                        noAttributes,
     243                        Type::Inline
     244                );
     245
     246                declsToAddAfter.push_back( get_decl );
     247
     248                get_decl->fixUniqueId();
     249        }
     250       
     251
     252        //=============================================================================================
    126253        // Mutex keyword implementation
    127254        //=============================================================================================
     
    137264                if( ! body ) return;
    138265
    139                 assert(monitor_decl);
     266                if( !monitor_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl );
     267                if( !guard_decl ) throw SemanticError( "mutex keyword requires monitors to be in scope, add #include <monitor>", decl );
     268
    140269                addStatments( body, mutexArgs );
    141270        }
     
    146275                        monitor_decl = decl;
    147276                }
     277                else if( decl->get_name() == "monitor_guard_t" ) {
     278                        assert( !guard_decl );
     279                        guard_decl = decl;
     280                }
    148281        }
    149282
     
    175308
    176309                //Make sure that typed isn't mutex
    177                 if( ! base->get_mutex() ) throw SemanticError( "mutex keyword may only appear once per argument ", arg );
     310                if( base->get_mutex() ) throw SemanticError( "mutex keyword may only appear once per argument ", arg );
    178311        }
    179312
    180313        void MutexKeyword::addStatments( CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
    181 
    182314                ObjectDecl * monitors = new ObjectDecl(
    183315                        "__monitors",
     
    218350                                new StructInstType(
    219351                                        noQualifiers,
    220                                         "monitor_guard_t"
     352                                        guard_decl
    221353                                ),
    222354                                new ListInit(
     
    224356                                                new SingleInit( new VariableExpr( monitors ) ),
    225357                                                new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) )
    226                                         }
     358                                        },
     359                                        noDesignators,
     360                                        true
    227361                                )
    228362                        ))
    229363                );
    230364
    231                 //monitor_desc * __monitors[] = { a, b };
     365                //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    232366                body->push_front( new DeclStmt( noLabels, monitors) );
    233367        }
  • src/Parser/DeclarationNode.cc

    r94a8123 r168c007  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 08:46:05 2017
    13 // Update Count     : 1017
     12// Last Modified On : Fri Mar 17 15:46:33 2017
     13// Update Count     : 1018
    1414//
    1515
     
    3636const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" };
    3737const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" };
    38 const char * DeclarationNode::aggregateNames[] = { "struct", "union", "context", "NoAggregateNames" };
     38const char * DeclarationNode::aggregateNames[] = { "struct", "union", "trait", "coroutine", "monitor", "thread", "NoAggregateNames" };
    3939const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };
    4040const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "NoBuiltinTypeNames" };
  • src/Parser/ParseNode.h

    r94a8123 r168c007  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:32:43 2017
    13 // Update Count     : 776
     12// Last Modified On : Fri Mar 17 15:42:18 2017
     13// Update Count     : 777
    1414//
    1515
     
    206206        enum Signedness { Signed, Unsigned, NoSignedness };
    207207        enum Length { Short, Long, LongLong, NoLength };
    208         enum Aggregate { Struct, Union, Trait, NoAggregate };
     208        enum Aggregate { Struct, Union, Trait, Coroutine, Monitor, Thread, NoAggregate };
    209209        enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };
    210210        enum BuiltinType { Valist, Zero, One, NoBuiltinType };
  • src/Parser/TypeData.cc

    r94a8123 r168c007  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 08:46:10 2017
    13 // Update Count     : 560
     12// Last Modified On : Fri Mar 17 15:52:43 2017
     13// Update Count     : 563
    1414//
    1515
     
    619619        switch ( td->aggregate.kind ) {
    620620          case DeclarationNode::Struct:
    621                 at = new StructDecl( *td->aggregate.name, attributes );
     621          case DeclarationNode::Coroutine:
     622          case DeclarationNode::Monitor:
     623          case DeclarationNode::Thread:
     624                at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes );
    622625                buildForall( td->aggregate.params, at->get_parameters() );
    623626                break;
     
    656659                          switch ( type->aggregate.kind ) {
    657660                                case DeclarationNode::Struct:
     661                                case DeclarationNode::Coroutine:
     662                                case DeclarationNode::Monitor:
     663                                case DeclarationNode::Thread:
    658664                                  ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
    659665                                  break;
     
    671677                          switch ( type->aggregate.kind ) {
    672678                                case DeclarationNode::Struct:
     679                                case DeclarationNode::Coroutine:
     680                                case DeclarationNode::Monitor:
     681                                case DeclarationNode::Thread:
    673682                                  ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    674683                                  break;
     
    703712                  switch ( type->aggregate.kind ) {
    704713                        case DeclarationNode::Struct:
     714                        case DeclarationNode::Coroutine:
     715                        case DeclarationNode::Monitor:
     716                        case DeclarationNode::Thread:
    705717                          ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    706718                          break;
  • src/Parser/lex.ll

    r94a8123 r168c007  
    202202__const__               { KEYWORD_RETURN(CONST); }                              // GCC
    203203continue                { KEYWORD_RETURN(CONTINUE); }
    204 _Coroutine              { KEYWORD_RETURN(COROUTINE); }                  // CFA
     204coroutine               { KEYWORD_RETURN(COROUTINE); }                  // CFA
    205205default                 { KEYWORD_RETURN(DEFAULT); }
    206206disable                 { KEYWORD_RETURN(DISABLE); }                    // CFA
  • src/Parser/parser.yy

    r94a8123 r168c007  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 12:57:03 2017
    13 // Update Count     : 2316
     12// Last Modified On : Fri Mar 17 15:42:22 2017
     13// Update Count     : 2317
    1414//
    1515
     
    16381638                { $$ = DeclarationNode::Union; }
    16391639        | COROUTINE
    1640                 { $$ = DeclarationNode::Struct; }
     1640                { $$ = DeclarationNode::Coroutine; }
    16411641        | MONITOR
    1642                 { $$ = DeclarationNode::Struct; }
     1642                { $$ = DeclarationNode::Monitor; }
    16431643        | THREAD
    1644                 { $$ = DeclarationNode::Struct; }
     1644                { $$ = DeclarationNode::Thread; }
    16451645        ;
    16461646
  • src/SynTree/Declaration.h

    r94a8123 r168c007  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:34:11 2017
    13 // Update Count     : 118
     12// Last Modified On : Fri Mar 17 16:05:08 2017
     13// Update Count     : 121
    1414//
    1515
     
    255255        typedef AggregateDecl Parent;
    256256  public:
    257         StructDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >() ) : Parent( name, attributes ) {}
     257        StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >() ) : Parent( name, attributes ), kind( kind ) {}
    258258        StructDecl( const StructDecl &other ) : Parent( other ) {}
    259259
     260        bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
     261        bool is_monitor() { return kind == DeclarationNode::Monitor; }
     262        bool is_thread() { return kind == DeclarationNode::Thread; }
     263
    260264        virtual StructDecl *clone() const { return new StructDecl( *this ); }
    261265        virtual void accept( Visitor &v ) { v.visit( this ); }
    262266        virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    263267  private:
     268        DeclarationNode::Aggregate kind;
    264269        virtual std::string typeString() const;
    265270};
  • src/SynTree/Type.h

    r94a8123 r168c007  
    117117                bool operator!=( Qualifiers other ) const { return (val & Mask) != (other.val & Mask); }
    118118                bool operator<=( Qualifiers other ) const {
    119                         return is_const <= other.is_const && is_volatile <= other.is_volatile &&
    120                                 is_mutex >= other.is_mutex && is_atomic == other.is_atomic;
     119                        return is_const    <= other.is_const        //Any non-const converts to const without cost
     120                                        && is_volatile <= other.is_volatile     //Any non-volatile converts to volatile without cost
     121                                        && is_mutex    >= other.is_mutex        //Any mutex converts to non-mutex without cost
     122                                        && is_atomic   == other.is_atomic;      //No conversion from atomic to non atomic is free
    121123                }
    122124                bool operator<( Qualifiers other ) const { return *this != other && *this <= other; }
  • src/benchmark/CorCtxSwitch.c

    r94a8123 r168c007  
    2424
    2525struct GreatSuspender {
    26         coroutine_desc c;
     26        coroutine_desc __cor;
    2727};
    2828
  • src/benchmark/bench.c

    r94a8123 r168c007  
    8686//=======================================
    8787
    88 struct CoroutineDummy { coroutine_desc c; };
     88struct CoroutineDummy { coroutine_desc __cor; };
    8989DECL_COROUTINE(CoroutineDummy);
    9090void main(CoroutineDummy * this) {}
     
    119119struct CoroutineResume {
    120120    int N;
    121     coroutine_desc c;
     121    coroutine_desc __cor;
    122122};
    123123
     
    150150//=======================================
    151151
    152 struct ThreadDummy { thread_desc t; };
     152struct ThreadDummy { thread_desc __thrd; };
    153153DECL_THREAD(ThreadDummy);
    154154void main(ThreadDummy * this) {}
     
    180180    int N;
    181181    long long result;
    182     thread_desc t;
     182    thread_desc __thrd;
    183183};
    184184
  • src/benchmark/csv-data.c

    r94a8123 r168c007  
    2626
    2727struct GreatSuspender {
    28         coroutine_desc c;
     28        coroutine_desc __cor;
    2929};
    3030
  • src/driver/Makefile.am

    r94a8123 r168c007  
    3232
    3333install-exec-hook:
     34        @test -z "$(CFA_BINDIR)" || $(MKDIR_P) "$(CFA_BINDIR)"
    3435        @echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) cfa '$(CFA_BINDIR)/$(CFA_NAME)'"; \
    3536        $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) cfa $(CFA_BINDIR)/$(CFA_NAME) || exit $$?
  • src/driver/Makefile.in

    r94a8123 r168c007  
    530530
    531531install-exec-hook:
     532        @test -z "$(CFA_BINDIR)" || $(MKDIR_P) "$(CFA_BINDIR)"
    532533        @echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) cfa '$(CFA_BINDIR)/$(CFA_NAME)'"; \
    533534        $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) cfa $(CFA_BINDIR)/$(CFA_NAME) || exit $$?
  • src/examples/multicore.c

    r94a8123 r168c007  
    22#include <thread>
    33
    4 struct MyThread { thread_desc t; };
     4struct MyThread { thread_desc __thrd; };
    55
    66DECL_THREAD(MyThread);
  • src/libcfa/concurrency/coroutine

    r94a8123 r168c007  
    3030};
    3131
    32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->c; } void main(X* this)
     32#define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X* this) { return &this->__cor; } void main(X* this)
    3333
    3434//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/invoke.c

    r94a8123 r168c007  
    5656
    5757void CtxInvokeThread(
     58      void (*dtor)(void *),
    5859      void (*main)(void *),
    5960      struct thread_desc *(*get_thread)(void *),
     
    6364
    6465      struct thread_desc* thrd = get_thread( this );
    65       struct coroutine_desc* cor = &thrd->c;
     66      struct coroutine_desc* cor = &thrd->cor;
    6667      cor->state = Active;
    6768
     
    9192        struct FakeStack {
    9293            void *fixedRegisters[3];                    // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant)
    93             uint32_t mxcr;                              // SSE Status and Control bits (control bits are preserved across function calls)
    94             uint16_t fcw;                               // X97 FPU control word (preserved across function calls)
    95             void *rturn;                                // where to go on return from uSwitch
     94            uint32_t mxcr;                        // SSE Status and Control bits (control bits are preserved across function calls)
     95          uint16_t fcw;                         // X97 FPU control word (preserved across function calls)
     96            void *rturn;                          // where to go on return from uSwitch
    9697            void *dummyReturn;                          // fake return compiler would have pushed on call to uInvoke
    9798            void *argument[3];                          // for 16-byte ABI, 16-byte alignment starts here
     
    105106        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = this;     // argument to invoke
    106107        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke;
     108      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
     109      ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    107110
    108111#elif defined( __x86_64__ )
    109112
    110113      struct FakeStack {
    111             void *fixedRegisters[5];                    // fixed registers rbx, r12, r13, r14, r15
    112             uint32_t mxcr;                              // SSE Status and Control bits (control bits are preserved across function calls)
    113             uint16_t fcw;                               // X97 FPU control word (preserved across function calls)
    114             void *rturn;                                // where to go on return from uSwitch
    115             void *dummyReturn;                          // NULL return address to provide proper alignment
     114            void *fixedRegisters[5];            // fixed registers rbx, r12, r13, r14, r15
     115            uint32_t mxcr;                      // SSE Status and Control bits (control bits are preserved across function calls)
     116            uint16_t fcw;                       // X97 FPU control word (preserved across function calls)
     117            void *rturn;                        // where to go on return from uSwitch
     118            void *dummyReturn;                  // NULL return address to provide proper alignment
    116119      };
    117120
  • src/libcfa/concurrency/invoke.h

    r94a8123 r168c007  
    2828      #define unlikely(x)    __builtin_expect(!!(x), 0)
    2929      #define thread_local _Thread_local
    30       #define SCHEDULER_CAPACITY 10
    3130
    3231      struct spinlock {
     
    6059
    6160      struct coStack_t {
    62             unsigned int size;                // size of stack
    63             void *storage;                            // pointer to stack
    64             void *limit;                              // stack grows towards stack limit
    65             void *base;                               // base of stack
    66             void *context;                            // address of cfa_context_t
    67             void *top;                                // address of top of storage
    68             bool userStack;     
     61            unsigned int size;                  // size of stack
     62            void *storage;                      // pointer to stack
     63            void *limit;                        // stack grows towards stack limit
     64            void *base;                         // base of stack
     65            void *context;                      // address of cfa_context_t
     66            void *top;                          // address of top of storage
     67            bool userStack;                     // whether or not the user allocated the stack
    6968      };
    7069
     
    7271
    7372      struct coroutine_desc {
    74             struct coStack_t stack;
    75             const char *name;                         // textual name for coroutine/task, initialized by uC++ generated code
    76             int errno_;                               // copy of global UNIX variable errno
    77             enum coroutine_state state;       // current execution status for coroutine
    78             struct coroutine_desc *starter;           // first coroutine to resume this one
    79             struct coroutine_desc *last;                      // last coroutine to resume this one
     73            struct coStack_t stack;             // stack information of the coroutine
     74            const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code
     75            int errno_;                         // copy of global UNIX variable errno
     76            enum coroutine_state state;         // current execution status for coroutine
     77            struct coroutine_desc *starter;     // first coroutine to resume this one
     78            struct coroutine_desc *last;              // last coroutine to resume this one
    8079      };
    8180
    8281      struct thread_desc {
    83             struct coroutine_desc c;                 // coroutine body used to store context
     82            struct coroutine_desc cor;            // coroutine body used to store context
    8483            struct signal_once terminated;      // indicate if execuation state is not halted
    85             struct thread_desc * next;               // instrusive link field for threads
     84            struct thread_desc * next;          // instrusive link field for threads
    8685      };
    8786
  • src/libcfa/concurrency/kernel.c

    r94a8123 r168c007  
    107107
    108108void ?{}( thread_desc * this, current_stack_info_t * info) {
    109         (&this->c){ info };
     109        (&this->cor){ info };
    110110}
    111111
     
    113113// Processor coroutine
    114114void ?{}(processorCtx_t * this, processor * proc) {
    115         (&this->c){};
     115        (&this->__cor){};
    116116        this->proc = proc;
    117117        proc->runner = this;
     
    119119
    120120void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) {
    121         (&this->c){ info };
     121        (&this->__cor){ info };
    122122        this->proc = proc;
    123123        proc->runner = this;
     
    255255        processorCtx_t proc_cor_storage = { proc, &info };
    256256
    257         LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.c.stack.base);
     257        LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);
    258258
    259259        //Set global state
    260         proc->current_coroutine = &proc->runner->c;
     260        proc->current_coroutine = &proc->runner->__cor;
    261261        proc->current_thread = NULL;
    262262
     
    268268        // back to here. Instead directly call the main since we already are on the
    269269        // appropriate stack.
    270         proc_cor_storage.c.state = Active;
     270        proc_cor_storage.__cor.state = Active;
    271271      main( &proc_cor_storage );
    272       proc_cor_storage.c.state = Halted;
     272      proc_cor_storage.__cor.state = Halted;
    273273
    274274        // Main routine of the core returned, the core is now fully terminated
     
    359359        this_processor = systemProcessor;
    360360        this_processor->current_thread = mainThread;
    361         this_processor->current_coroutine = &mainThread->c;
     361        this_processor->current_coroutine = &mainThread->cor;
    362362
    363363        // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
  • src/libcfa/concurrency/kernel_private.h

    r94a8123 r168c007  
    3535struct processorCtx_t {
    3636        processor * proc;
    37         coroutine_desc c;
     37        coroutine_desc __cor;
    3838};
    3939
  • src/libcfa/concurrency/monitor

    r94a8123 r168c007  
    3434}
    3535
    36 //Basic entering routine
    37 void enter(monitor_desc *);
    38 void leave(monitor_desc *);
    39 
    4036//Array entering routine
    4137void enter(monitor_desc **, int count);
     
    4945static inline int ?<?(monitor_desc* lhs, monitor_desc* rhs) {
    5046        return ((intptr_t)lhs) < ((intptr_t)rhs);
    51 }
    52 
    53 static inline void ?{}( monitor_guard_t * this, monitor_desc ** m ) {
    54         this->m = m;
    55         this->count = 1;
    56         enter( *this->m );
    5747}
    5848
  • src/libcfa/concurrency/monitor.c

    r94a8123 r168c007  
    7474void enter(monitor_desc ** monitors, int count) {
    7575        for(int i = 0; i < count; i++) {
    76                 // printf("%d\n", i);
    7776                enter( monitors[i] );
    7877        }
     
    8180void leave(monitor_desc ** monitors, int count) {
    8281        for(int i = count - 1; i >= 0; i--) {
    83                 // printf("%d\n", i);
    8482                leave( monitors[i] );
    8583        }
  • src/libcfa/concurrency/thread

    r94a8123 r168c007  
    2828// Anything that is resumed is a coroutine.
    2929trait is_thread(dtype T) {
     30      void ^?{}(T* this);
    3031      void main(T* this);
    3132      thread_desc* get_thread(T* this);
    3233};
    3334
    34 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->t; } void main(X* this)
     35#define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this)
    3536
    3637forall( dtype T | is_thread(T) )
    3738static inline coroutine_desc* get_coroutine(T* this) {
    38         return &get_thread(this)->c;
     39        return &get_thread(this)->cor;
    3940}
    4041
    4142static inline coroutine_desc* get_coroutine(thread_desc* this) {
    42         return &this->c;
     43        return &this->cor;
    4344}
    4445
     
    6465void ?{}( scoped(T)* this, P params );
    6566
    66 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
     67forall( dtype T | sized(T) | is_thread(T) )
    6768void ^?{}( scoped(T)* this );
    6869
  • src/libcfa/concurrency/thread.c

    r94a8123 r168c007  
    4242
    4343void ?{}(thread_desc* this) {
    44         (&this->c){};
    45         this->c.name = "Anonymous Coroutine";
     44        (&this->cor){};
     45        this->cor.name = "Anonymous Coroutine";
    4646        (&this->terminated){};
    4747        this->next = NULL;
     
    4949
    5050void ^?{}(thread_desc* this) {
    51         ^(&this->c){};
     51        ^(&this->cor){};
    5252}
    5353
     
    6464}
    6565
    66 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
     66forall( dtype T | sized(T) | is_thread(T) )
    6767void ^?{}( scoped(T)* this ) {
    6868        stop(&this->handle);
     
    120120extern "C" {
    121121        void __thread_signal_termination( thread_desc * this ) {
    122                 this->c.state = Halted;
     122                this->cor.state = Halted;
    123123                LIB_DEBUG_PRINTF("Thread end : %p\n", this);
    124124                signal( &this->terminated );   
  • src/main.cc

    r94a8123 r168c007  
    241241                OPTPRINT( "fixNames" )
    242242                CodeGen::fixNames( translationUnit );
    243                 OPTPRINT( "tweakInit" )
     243                OPTPRINT( "genInit" )
    244244                InitTweak::genInit( translationUnit );
    245245                OPTPRINT( "expandMemberTuples" );
  • src/tests/coroutine.c

    r94a8123 r168c007  
    22#include <coroutine>
    33
    4 struct Fibonacci {
     4coroutine Fibonacci {
    55      int fn; // used for communication
    6       coroutine_desc c;
    76};
    87
     
    1110}
    1211
    13 coroutine_desc* get_coroutine(Fibonacci* this) {
    14       return &this->c;
    15 }
    16 
    1712void main(Fibonacci* this) {
    18 #ifdef MORE_DEBUG
    19       sout | "Starting main of coroutine " | this | endl;
    20       sout | "Started from " | this->c.last | endl;
    21 #endif
    2213      int fn1, fn2;             // retained between resumes
    2314      this->fn = 0;
     
    4536int main() {
    4637      Fibonacci f1, f2;
    47 #ifdef MORE_DEBUG     
    48       Fibonacci *pf1 = &f1, *pf2 = &f2;
    49       coroutine_desc *cf1 = &f1.c, *cf2 = &f2.c;
    50       covptr_t  *vf1 = vtable(pf1), *vf2 = vtable(pf2);
    51       coroutine_desc *cv1 = get_coroutine(vf1), *cv2 = get_coroutine(vf2);
    52       Fibonacci *ov1 = (Fibonacci *)get_object(vf1), *ov2 = (Fibonacci *)get_object(vf2);
    53 
    54       sout | "User coroutines : " | pf1 | ' ' | pf2 | endl;
    55       sout | "Coroutine data  : " | cf1 | ' ' | cf2 | endl;
    56       sout | "Vptr address    : " | vf1 | ' ' | vf2 | endl;
    57       sout | "Vptr obj data   : " | ov1 | ' ' | ov2 | endl;
    58       sout | "Vptr cor data   : " | cv1 | ' ' | cv2 | endl;
    59 #endif
    6038      for ( int i = 1; i <= 10; i += 1 ) {
    6139            sout | next(&f1) | ' ' | next(&f2) | endl;
  • src/tests/monitor.c

    r94a8123 r168c007  
    1313}
    1414
     15monitor_desc * get_monitor( global_t * this ) {
     16        return &this->m;
     17}
     18
    1519static global_t global;
    1620
    17 void increment( /*mutex*/ global_t * this ) {
    18         monitor_desc * mon = &this->m;
    19         monitor_guard_t g1 = { &mon };
    20         {
    21                 monitor_guard_t g2 = { &mon };
    22                 {
    23                         monitor_guard_t g3 = { &mon };
    24                         this->value += 1;
    25                 }
    26         }
     21void increment3( global_t * mutex this ) {
     22        this->value += 1;
    2723}
    2824
    29 struct MyThread { thread_desc t; };
     25void increment2( global_t * mutex this ) {
     26        increment3( this );
     27}
     28
     29void increment( global_t * mutex this ) {
     30        increment2( this );
     31}
     32
     33struct MyThread { thread_desc __thrd; };
    3034
    3135DECL_THREAD(MyThread);
  • src/tests/multi-monitor.c

    r94a8123 r168c007  
    66static int global12, global23, global13;
    77
    8 static monitor_desc m1, m2, m3;
     8struct monitor_t {
     9        monitor_desc m;
     10};
    911
    10 void increment( /*mutex*/ monitor_desc * p1, /*mutex*/ monitor_desc * p2, int * value ) {
    11         monitor_desc * mons[] = { p1, p2 };
    12         monitor_guard_t g = { mons, 2 };
     12monitor_desc * get_monitor( monitor_t * this ) {
     13        return &this->m;
     14}
     15
     16static monitor_t m1, m2, m3;
     17
     18void increment( monitor_t * mutex p1, monitor_t * mutex p2, int * value ) {
    1319        *value += 1;
    1420}
    1521
    1622struct MyThread {
    17         thread_desc t;
     23        thread_desc __thrd;
    1824        int target;
    1925};
  • src/tests/thread.c

    r94a8123 r168c007  
    44#include <thread>
    55
    6 struct First { thread_desc t; signal_once* lock; };
    7 struct Second { thread_desc t; signal_once* lock; };
     6struct First { thread_desc __thrd; signal_once* lock; };
     7struct Second { thread_desc __thrd; signal_once* lock; };
    88
    99DECL_THREAD(First);
Note: See TracChangeset for help on using the changeset viewer.