Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/monitor.c

    rbe3d020 r44264c5  
    137137}
    138138
    139 void ?{}(__condition_node_t * this, thread_desc * waiting_thread, unsigned short count, uintptr_t user_info ) {
    140         this->waiting_thread = waiting_thread;
    141         this->count = count;
    142         this->next = NULL;
    143         this->user_info = user_info;
    144 }
    145 
    146 void ?{}(__condition_criterion_t * this ) {
    147         this->ready  = false;
    148         this->target = NULL;
    149         this->owner  = NULL;
    150         this->next   = NULL;
    151 }
    152 
    153 void ?{}(__condition_criterion_t * this, monitor_desc * target, __condition_node_t * owner ) {
    154         this->ready  = false;
    155         this->target = target;
    156         this->owner  = owner;
    157         this->next   = NULL;
     139void debug_break() __attribute__(( noinline ))
     140{
     141       
    158142}
    159143
    160144//-----------------------------------------------------------------------------
    161145// Internal scheduling
    162 void wait( condition * this, uintptr_t user_info = 0 ) {
     146void wait( condition * this ) {
    163147        LIB_DEBUG_PRINT_SAFE("Waiting\n");
    164148
     
    176160        LIB_DEBUG_PRINT_SAFE("count %i\n", count);
    177161
    178         __condition_node_t waiter = { this_thread(), count, user_info };
     162        __condition_node_t waiter;
     163        waiter.waiting_thread = this_thread();
     164        waiter.count = count;
     165        waiter.next = NULL;
    179166
    180167        __condition_criterion_t criteria[count];
    181168        for(int i = 0; i < count; i++) {
    182                 (&criteria[i]){ this->monitors[i], &waiter };
     169                criteria[i].ready  = false;
     170                criteria[i].target = this->monitors[i];
     171                criteria[i].owner  = &waiter;
     172                criteria[i].next   = NULL;
    183173                LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
    184174        }
     
    212202        ScheduleInternal( locks, count, threads, thread_count );
    213203
     204        debug_break();
    214205        //WE WOKE UP
    215206
     
    221212}
    222213
    223 bool signal( condition * this ) {
    224         if( is_empty( this ) ) {
     214void signal( condition * this ) {
     215        if( !this->blocked.head ) {
    225216                LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
    226                 return false;
     217                return;
    227218        }
    228219
     
    266257        //Release
    267258        unlock_all( this->monitors, count );
    268 
    269         return true;
    270 }
    271 
    272 bool signal_block( condition * this ) {
     259}
     260
     261void signal_block( condition * this ) {
    273262        if( !this->blocked.head ) {
    274263                LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
    275                 return false;
     264                return;
    276265        }
    277266
     
    287276
    288277        //create creteria
    289         __condition_node_t waiter = { this_thread(), count, 0 };
     278        __condition_node_t waiter;
     279        waiter.waiting_thread = this_thread();
     280        waiter.count = count;
     281        waiter.next = NULL;
    290282
    291283        __condition_criterion_t criteria[count];
    292284        for(int i = 0; i < count; i++) {
    293                 (&criteria[i]){ this->monitors[i], &waiter };
    294285                LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
     286                criteria[i].ready  = false;
     287                criteria[i].owner  = &waiter;
     288                criteria[i].next   = NULL;
     289                criteria[i].target = this->monitors[i];
    295290                push( &criteria[i].target->signal_stack, &criteria[i] );
    296291        }
     
    308303
    309304        LIB_DEBUG_PRINT_SAFE( "Waiting on signal block\n" );
     305        debug_break();
    310306
    311307        //Everything is ready to go to sleep
    312308        ScheduleInternal( locks, count, &signallee, 1 );
    313309
     310        debug_break();
    314311        LIB_DEBUG_PRINT_SAFE( "Back from signal block\n" );
    315312
     
    318315        restore_recursion( this->monitors, recursions, count );
    319316        unlock_all( locks, count );
    320 
    321         return true;
    322 }
    323 
    324 uintptr_t front( condition * this ) {
    325         LIB_DEBUG_DO(
    326                 if( is_empty(this) ) {
    327                         abortf( "Attempt to access user data on an empty condition.\n"
    328                     "Possible cause is not checking if the condition is empty before reading stored data." );
    329                 }
    330         );
    331         return this->blocked.head->user_info;
    332317}
    333318
Note: See TracChangeset for help on using the changeset viewer.