Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r9243cc91 r64adb03  
    8888        //Handles mutex routines definitions :
    8989        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    90         //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
     90        //                                                                       monitor_desc * __monitors[] = { a, b };
    9191        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    9292        //    /*Some code*/                                       =>           /*Some code*/
     
    9898                using Visitor::visit;
    9999                virtual void visit( FunctionDecl *functionDecl ) override final;
    100                 virtual void visit(   StructDecl *functionDecl ) override final;
    101100
    102101                std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );
     
    108107                        acceptAll( translationUnit, impl );
    109108                }
    110 
    111           private:
    112                 StructDecl* monitor_decl = nullptr;
    113109        };
    114110
     
    137133                if( ! body ) return;
    138134
    139                 assert(monitor_decl);
    140135                addStatments( body, mutexArgs );
    141         }
    142 
    143         void MutexKeyword::visit(StructDecl* decl) {
    144                 if( decl->get_name() == "monitor_desc" ) {
    145                         assert( !monitor_decl );
    146                         monitor_decl = decl;
    147                 }
    148136        }
    149137
     
    179167
    180168        void MutexKeyword::addStatments( CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
    181 
    182                 ObjectDecl * monitors = new ObjectDecl(
    183                         "__monitors",
    184                         noStorage,
    185                         LinkageSpec::Cforall,
    186                         nullptr,
    187                         new ArrayType(
    188                                 noQualifiers,
    189                                 new PointerType(
    190                                         noQualifiers,
    191                                         new StructInstType(
    192                                                 noQualifiers,
    193                                                 monitor_decl
    194                                         )
    195                                 ),
    196                                 new ConstantExpr( Constant::from_ulong( args.size() ) ),
    197                                 false,
    198                                 false
    199                         ),
    200                         new ListInit(
    201                                 map_range < std::list<Initializer*> > ( args, [](DeclarationWithType * var ){
    202                                         return new SingleInit( new UntypedExpr(
    203                                                 new NameExpr( "get_monitor" ),
    204                                                 {  new VariableExpr( var ) }
    205                                         ) );
    206                                 })
    207                         )
    208                 );
    209 
    210169                //in reverse order :
    211170                // monitor_guard_t __guard = { __monitors, # };
     
    222181                                new ListInit(
    223182                                        {
    224                                                 new SingleInit( new VariableExpr( monitors ) ),
     183                                                new SingleInit( new NameExpr( "__monitors" ) ),
    225184                                                new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) )
    226185                                        }
     
    230189
    231190                //monitor_desc * __monitors[] = { a, b };
    232                 body->push_front( new DeclStmt( noLabels, monitors) );
     191                body->push_front(
     192                        new DeclStmt( noLabels, new ObjectDecl(
     193                                "__monitors",
     194                                noStorage,
     195                                LinkageSpec::Cforall,
     196                                nullptr,
     197                                new ArrayType(
     198                                        noQualifiers,
     199                                        new PointerType(
     200                                                noQualifiers,
     201                                                new StructInstType(
     202                                                        noQualifiers,
     203                                                        "monitor_desc"
     204                                                )
     205                                        ),
     206                                        new ConstantExpr( Constant::from_ulong( args.size() ) ),
     207                                        false,
     208                                        false
     209                                ),
     210                                new ListInit(
     211                                        map_range < std::list<Initializer*> > ( args, [](DeclarationWithType * var ){
     212                                                return new SingleInit( new VariableExpr( var ) );
     213                                        })
     214                                )
     215                        ))
     216                );
    233217        }
    234218};
Note: See TracChangeset for help on using the changeset viewer.