Ignore:
Timestamp:
May 29, 2018, 4:17:30 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
6c7099a
Parents:
8ebbfc4
Message:

First draft at locks in Cforall

File:
1 edited

Legend:

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

    r8ebbfc4 r09800e9  
    4949thread_desc * mainThread;
    5050
    51 struct { __dllist_t(cluster    ) list; __spinlock_t lock; } global_clusters;
     51struct { __dllist_t(cluster) list; __spinlock_t lock; } global_clusters;
    5252
    5353//-----------------------------------------------------------------------------
     
    257257// its final actions must be executed from the kernel
    258258void finishRunning(processor * this) with( this->finish ) {
    259         if( action_code == Release ) {
    260                 verify( ! kernelTLS.preemption_state.enabled );
     259        verify( ! kernelTLS.preemption_state.enabled );
     260        choose( action_code ) {
     261        case No_Action:
     262                break;
     263        case Release:
    261264                unlock( *lock );
    262         }
    263         else if( action_code == Schedule ) {
     265        case Schedule:
    264266                ScheduleThread( thrd );
    265         }
    266         else if( action_code == Release_Schedule ) {
    267                 verify( ! kernelTLS.preemption_state.enabled );
     267        case Release_Schedule:
    268268                unlock( *lock );
    269269                ScheduleThread( thrd );
    270         }
    271         else if( action_code == Release_Multi ) {
    272                 verify( ! kernelTLS.preemption_state.enabled );
     270        case Release_Multi:
    273271                for(int i = 0; i < lock_count; i++) {
    274272                        unlock( *locks[i] );
    275273                }
    276         }
    277         else if( action_code == Release_Multi_Schedule ) {
     274        case Release_Multi_Schedule:
    278275                for(int i = 0; i < lock_count; i++) {
    279276                        unlock( *locks[i] );
     
    282279                        ScheduleThread( thrds[i] );
    283280                }
    284         }
    285         else {
    286                 assert(action_code == No_Action);
     281        case Callback:
     282                callback();
     283        default:
     284                abort("KERNEL ERROR: Unexpected action to run after thread");
    287285        }
    288286}
     
    497495}
    498496
     497void BlockInternal(__finish_callback_fptr_t callback) {
     498        disable_interrupts();
     499        with( *kernelTLS.this_processor ) {
     500                finish.action_code = Callback;
     501                finish.callback    = callback;
     502        }
     503
     504        verify( ! kernelTLS.preemption_state.enabled );
     505        returnToKernel();
     506        verify( ! kernelTLS.preemption_state.enabled );
     507
     508        enable_interrupts( __cfaabi_dbg_ctx );
     509}
     510
    499511// KERNEL ONLY
    500512void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
Note: See TracChangeset for help on using the changeset viewer.