- Timestamp:
- Feb 28, 2017, 4:21:15 PM (8 years ago)
- 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:
- 20221d4
- Parents:
- cc7f4b1
- Location:
- src
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/monitor
rcc7f4b1 r2781e65 20 20 #include "assert" 21 21 #include "invoke.h" 22 #include "stdlib" 22 23 23 24 struct __monitor_t { … … 33 34 } 34 35 36 //Basic entering routine 35 37 void enter(__monitor_t *); 36 38 void leave(__monitor_t *); 37 39 40 //Array entering routine 41 void enter(__monitor_t **, int count); 42 void leave(__monitor_t **, int count); 43 38 44 struct monitor_guard_t { 39 __monitor_t * m; 45 __monitor_t ** m; 46 int count; 40 47 }; 41 48 42 static inline void ?{}( monitor_guard_t * this, __monitor_t * m ) { 49 static inline int ?<?(__monitor_t* lhs, __monitor_t* rhs) { 50 return ((intptr_t)lhs) < ((intptr_t)rhs); 51 } 52 53 static inline void ?{}( monitor_guard_t * this, __monitor_t ** m ) { 43 54 this->m = m; 44 enter( this->m ); 55 this->count = 1; 56 enter( *this->m ); 57 } 58 59 static inline void ?{}( monitor_guard_t * this, __monitor_t ** m, int count ) { 60 this->m = m; 61 this->count = count; 62 qsort(this->m, count); 63 enter( this->m, this->count ); 45 64 } 46 65 47 66 static inline void ^?{}( monitor_guard_t * this ) { 48 leave( this->m );67 leave( this->m, this->count ); 49 68 } 50 69 70 51 71 #endif //MONITOR_H -
src/libcfa/concurrency/monitor.c
rcc7f4b1 r2781e65 71 71 } 72 72 } 73 74 void enter(__monitor_t ** monitors, int count) { 75 for(int i = 0; i < count; i++) { 76 // printf("%d\n", i); 77 enter( monitors[i] ); 78 } 79 } 80 81 void leave(__monitor_t ** monitors, int count) { 82 for(int i = count - 1; i >= 0; i--) { 83 // printf("%d\n", i); 84 leave( monitors[i] ); 85 } 86 } -
src/tests/monitor.c
rcc7f4b1 r2781e65 16 16 17 17 void increment( /*mutex*/ global_t * this ) { 18 monitor_guard_t g1 = { &this->m }; 18 __monitor_t * mon = &this->m; 19 monitor_guard_t g1 = { &mon }; 19 20 { 20 monitor_guard_t g2 = { & this->m};21 monitor_guard_t g2 = { &mon }; 21 22 { 22 monitor_guard_t g3 = { & this->m};23 monitor_guard_t g3 = { &mon }; 23 24 this->value += 1; 24 25 }
Note: See TracChangeset
for help on using the changeset viewer.