Changeset a76da32 for libcfa/src/concurrency/kernel.hfa
- Timestamp:
- Feb 17, 2021, 10:09:04 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 1294d7f, f4f3f59
- Parents:
- 1717b12 (diff), 830299f (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.hfa
r1717b12 ra76da32 34 34 #endif 35 35 36 extern "C" {37 char * strerror(int);38 }39 #define CHECKED(x) { int err = x; if( err != 0 ) abort("KERNEL ERROR: Operation \"" #x "\" return error %d - %s\n", err, strerror(err)); }40 41 36 struct __bin_sem_t { 42 37 pthread_mutex_t lock; … … 44 39 int val; 45 40 }; 46 47 static inline void ?{}(__bin_sem_t & this) with( this ) {48 // Create the mutex with error checking49 pthread_mutexattr_t mattr;50 pthread_mutexattr_init( &mattr );51 pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_ERRORCHECK_NP);52 pthread_mutex_init(&lock, &mattr);53 54 pthread_cond_init (&cond, (const pthread_condattr_t *)0p); // workaround trac#208: cast should not be required55 val = 0;56 }57 58 static inline void ^?{}(__bin_sem_t & this) with( this ) {59 CHECKED( pthread_mutex_destroy(&lock) );60 CHECKED( pthread_cond_destroy (&cond) );61 }62 63 static inline void wait(__bin_sem_t & this) with( this ) {64 verify(__cfaabi_dbg_in_kernel());65 CHECKED( pthread_mutex_lock(&lock) );66 while(val < 1) {67 pthread_cond_wait(&cond, &lock);68 }69 val -= 1;70 CHECKED( pthread_mutex_unlock(&lock) );71 }72 73 static inline bool post(__bin_sem_t & this) with( this ) {74 bool needs_signal = false;75 76 CHECKED( pthread_mutex_lock(&lock) );77 if(val < 1) {78 val += 1;79 pthread_cond_signal(&cond);80 needs_signal = true;81 }82 CHECKED( pthread_mutex_unlock(&lock) );83 84 return needs_signal;85 }86 87 #undef CHECKED88 89 41 90 42 //-----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.