Changeset ef42b143


Ignore:
Timestamp:
Mar 16, 2017, 5:20:16 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
3743983
Parents:
1fbab5a
Message:

Implemented monitor keyword, and it works

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    r1fbab5a ref42b143  
    111111          private:
    112112                StructDecl* monitor_decl = nullptr;
     113                StructDecl* guard_decl = nullptr;
    113114        };
    114115
     
    137138                if( ! body ) return;
    138139
    139                 assert(monitor_decl);
    140140                addStatments( body, mutexArgs );
    141141        }
     
    146146                        monitor_decl = decl;
    147147                }
     148                else if( decl->get_name() == "monitor_guard_t" ) {
     149                        assert( !guard_decl );
     150                        guard_decl = decl;
     151                }
    148152        }
    149153
     
    175179
    176180                //Make sure that typed isn't mutex
    177                 if( ! base->get_qualifiers().isMutex ) throw SemanticError( "mutex keyword may only appear once per argument ", arg );
     181                if( base->get_qualifiers().isMutex ) throw SemanticError( "mutex keyword may only appear once per argument ", arg );
    178182        }
    179183
    180184        void MutexKeyword::addStatments( CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
     185                assert(monitor_decl);
     186                assert(guard_decl);
    181187
    182188                ObjectDecl * monitors = new ObjectDecl(
     
    218224                                new StructInstType(
    219225                                        noQualifiers,
    220                                         "monitor_guard_t"
     226                                        guard_decl
    221227                                ),
    222228                                new ListInit(
     
    224230                                                new SingleInit( new VariableExpr( monitors ) ),
    225231                                                new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) )
    226                                         }
     232                                        },
     233                                        noDesignators,
     234                                        true
    227235                                )
    228236                        ))
    229237                );
    230238
    231                 //monitor_desc * __monitors[] = { a, b };
     239                //monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    232240                body->push_front( new DeclStmt( noLabels, monitors) );
    233241        }
  • src/SynTree/Type.h

    r1fbab5a ref42b143  
    9292                bool operator<=( Qualifiers other ) const {
    9393                        return isConst <= other.isConst && isVolatile <= other.isVolatile &&
    94                                 isMutex == other.isMutex && isAtomic == other.isAtomic;
     94                                isMutex >= other.isMutex && isAtomic == other.isAtomic;
    9595                }
    9696                bool operator>=( Qualifiers other ) const {
    9797                        return isConst >= other.isConst && isVolatile >= other.isVolatile &&
    98                                 isMutex == other.isMutex && isAtomic == other.isAtomic;
     98                                isMutex <= other.isMutex && isAtomic == other.isAtomic;
    9999                }
    100100                bool operator<( Qualifiers other ) const {
  • src/main.cc

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

    r1fbab5a ref42b143  
    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;
     23}
     24
     25void increment2( global_t * mutex this ) {
     26        increment3( this );
     27}
     28
     29void increment( global_t * mutex this ) {
     30        increment2( this );
    2731}
    2832
  • src/tests/multi-monitor.c

    r1fbab5a ref42b143  
    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}
Note: See TracChangeset for help on using the changeset viewer.