Changeset 5c931e0 for libcfa/src


Ignore:
Timestamp:
Jan 9, 2023, 4:07:45 PM (16 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
cca034e
Parents:
72abfdd
Message:

made changes to support zero-size channels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/channel.hfa

    r72abfdd r5c931e0  
    1616
    1717forall( T ) {
    18 struct __attribute__ ((aligned (64))) channel {
     18struct channel {
    1919    size_t size;
    2020    size_t front, back, count;
     
    4949    lock( mutex_lock );
    5050
     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
    5159    // wait if buffer is full, work will be completed by someone else
    5260    if ( count == size ) {
     
    5563    } // if
    5664
    57     if ( count == 0 && !empty( prods ) )
     65    if ( count == 0 && !empty( cons ) )
    5866        // do waiting consumer work
    59         memcpy((void *)front( prods ), (void *)&elem, sizeof(T));
     67        memcpy((void *)front( cons ), (void *)&elem, sizeof(T));
    6068    else insert_( chan, elem );
    6169   
    62     notify_one( prods );
     70    notify_one( cons );
    6371    unlock( mutex_lock );
    6472}
     
    6876    T retval;
    6977
     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
    7086    // wait if buffer is empty, work will be completed by someone else
    7187    if (count == 0) {
    72         wait( prods, mutex_lock, (uintptr_t)&retval );
     88        wait( cons, mutex_lock, (uintptr_t)&retval );
    7389        return retval;
    7490    }
Note: See TracChangeset for help on using the changeset viewer.