Changeset c5bbb9b for libcfa/src


Ignore:
Timestamp:
Nov 5, 2020, 3:33:28 PM (3 years ago)
Author:
Colby Alexander Parsons <caparsons@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f4e35326
Parents:
eeb5023
Message:

removed test program from locks.cfa

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/locks.cfa

    reeb5023 rc5bbb9b  
    236236forall(dtype L | is_blocking_lock(L)) {
    237237
    238         void timeout_handler ( condition_variable(L) * cond , info_thread(L) ** i ) {
     238        void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) {
    239239        // This condition_variable member is called from the kernel, and therefore, cannot block, but it can spin.
    240240            lock( cond->lock __cfaabi_dbg_ctx2 );
     
    242242                info_thread(L) * copy = *i;
    243243                        remove( cond->blocked_threads, i );              //remove this thread O(1)
     244                        cond->wait_count--;
    244245                        if( !copy->lock ) {
    245246                                unlock( cond->lock );
    246                                 printf("here");
    247247                                #if !defined( __CFA_NO_STATISTICS__ )
    248248                                        kernelTLS.this_stats = copy->t->curr_cluster->stats;
    249249                                #endif
    250250                                unpark( copy->t );
    251                                 printf("here2");
    252251                } else {
    253252                        add_(*copy->lock, copy->t);                     // call lock's add_
     
    257256        }
    258257
    259         void alarm_node_callback( alarm_node_wrap(L) & this ) with( this ) {
    260                 timeout_handler(cond, i);
    261         }
    262 
    263258        void alarm_node_wrap_cast( alarm_node_t & a ) {
    264                 alarm_node_callback( (alarm_node_wrap(L) &)a );
     259                timeout_handler( (alarm_node_wrap(L) &)a );
    265260        }
    266261
     
    289284                popped->listed = false;
    290285                if(popped != 0p) {
    291                         add_(*popped->lock, popped->t);
    292286                        count--;
     287                        if (popped->lock) {
     288                                add_(*popped->lock, popped->t);
     289                        } else {
     290                                unpark(popped->t);
     291                        }
    293292                }
    294293                unlock( lock );
     
    303302                        popped->listed = false;
    304303                        if(popped != 0p){
    305                                 add_(*popped->lock, popped->t);
    306304                                count--;
     305                                if (popped->lock) {
     306                                        add_(*popped->lock, popped->t);
     307                                } else {
     308                                        unpark(popped->t);
     309                                }
    307310                        }
    308311                }
     
    436439        }
    437440}
    438 
    439 thread T1 {};
    440 thread T2 {};
    441 
    442 recursive_mutex_lock m;
    443 condition_variable( recursive_mutex_lock ) c;
    444 
    445 void main( T1 & this ) {
    446         printf("T1 start\n");
    447         lock(m);
    448         printf("%d\n", counter(c));
    449         if(empty(c)) {
    450                 printf("T1 wait\n");
    451                 wait(c,m,12);
    452         }else{
    453                 printf("%d\n", front(c));
    454                 notify_one(c);
    455         }
    456         unlock(m);
    457         printf("curr thd in main %p \n", kernelTLS.this_thread);
    458         printf("T1 waits for 2s\n");
    459         lock(m);
    460         wait( c, m, 2`s );
    461         unlock(m);
    462         printf("T1 wakes\n");
    463         printf("T1 done\n");
    464 }
    465 
    466 void main( T2 & this ) {
    467         printf("T2 start\n");
    468         lock(m);
    469         printf("%d\n", counter(c));
    470         if(empty(c)) {
    471                 printf("T2 wait\n");
    472                 wait(c,m,12);
    473         }else{
    474                 printf("%d\n", front(c));
    475                 notify_one(c);
    476         }
    477         unlock(m);
    478         printf("T2 done\n");
    479 }
    480 
    481 int main() {
    482         printf("start\n");
    483         processor p[2];
    484         {
    485                 T1 t1;
    486                 T2 t2;
    487         }
    488         printf("done\n");
    489 }
Note: See TracChangeset for help on using the changeset viewer.