- Timestamp:
- Jan 9, 2023, 4:07:45 PM (19 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- cca034e
- Parents:
- 72abfddd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/channel.hfa
r72abfddd r5c931e0 16 16 17 17 forall( T ) { 18 struct __attribute__ ((aligned (64)))channel {18 struct channel { 19 19 size_t size; 20 20 size_t front, back, count; … … 49 49 lock( mutex_lock ); 50 50 51 // have to check for the zero size channel case 52 if ( size == 0 && !empty( cons ) ) { 53 memcpy((void *)front( cons ), (void *)&elem, sizeof(T)); 54 notify_one( cons ); 55 unlock( mutex_lock ); 56 return; 57 } 58 51 59 // wait if buffer is full, work will be completed by someone else 52 60 if ( count == size ) { … … 55 63 } // if 56 64 57 if ( count == 0 && !empty( prods ) )65 if ( count == 0 && !empty( cons ) ) 58 66 // do waiting consumer work 59 memcpy((void *)front( prods ), (void *)&elem, sizeof(T));67 memcpy((void *)front( cons ), (void *)&elem, sizeof(T)); 60 68 else insert_( chan, elem ); 61 69 62 notify_one( prods );70 notify_one( cons ); 63 71 unlock( mutex_lock ); 64 72 } … … 68 76 T retval; 69 77 78 // have to check for the zero size channel case 79 if ( size == 0 && !empty( prods ) ) { 80 memcpy((void *)&retval, (void *)front( prods ), sizeof(T)); 81 notify_one( prods ); 82 unlock( mutex_lock ); 83 return retval; 84 } 85 70 86 // wait if buffer is empty, work will be completed by someone else 71 87 if (count == 0) { 72 wait( prods, mutex_lock, (uintptr_t)&retval );88 wait( cons, mutex_lock, (uintptr_t)&retval ); 73 89 return retval; 74 90 }
Note: See TracChangeset
for help on using the changeset viewer.