Changeset 51f3798


Ignore:
Timestamp:
Feb 23, 2017, 5:10:50 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:
6ce9f7c7
Parents:
ead8c7e
Message:

Added raii guard for monitors

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/monitor

    read8c7e r51f3798  
    3030void leave(monitor *);
    3131
     32struct monitor_guard {
     33        monitor * m;
     34};
     35
     36static inline void ?{}( monitor_guard * this, monitor * m ) {
     37        this->m = m;
     38        enter( this->m );
     39}
     40
     41static inline void ^?{}( monitor_guard * this ) {
     42        leave( this->m );
     43}
     44
    3245#endif //MONITOR_H
  • src/libcfa/concurrency/monitor.c

    read8c7e r51f3798  
    4444
    4545        unlock( &this->lock );
     46
    4647        if( this->holder ) ScheduleThread( this->holder );
    4748}
  • src/tests/monitor.c

    read8c7e r51f3798  
    1616
    1717void increment( /*mutex*/ global_t * this ) {
    18         enter( &this->m );
     18        monitor_guard g = { &this->m };
    1919        this->value += 1;
    20         leave( &this->m );
    2120}
    2221
Note: See TracChangeset for help on using the changeset viewer.