Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel

    reafb094 re15df4c  
    99//
    1010// Author           : Thierry Delisle
    11 // Created On       : Tue Jan 17 12:27:26 2017
     11// Created On       : Tue Jan 17 12:27:26 2016
    1212// Last Modified By : Thierry Delisle
    1313// Last Modified On : --
     
    2727
    2828//-----------------------------------------------------------------------------
    29 // Locks
    30 void lock( spinlock * );
    31 void unlock( spinlock * );
    32 
    33 void wait( signal_once * );
    34 void signal( signal_once * );
    35 
    36 //-----------------------------------------------------------------------------
    3729// Cluster
    3830struct cluster {
    3931        simple_thread_list ready_queue;
    40         spinlock lock;
     32        pthread_spinlock_t lock;
    4133};
    4234
     
    4638//-----------------------------------------------------------------------------
    4739// Processor
    48 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule };
    49 struct FinishAction {
    50         FinishOpCode action_code;
    51         thread * thrd;
    52         spinlock * lock;
    53 };
    54 static inline void ?{}(FinishAction * this) {
    55         this->action_code = No_Action;
    56         this->thrd = NULL;
    57         this->lock = NULL;
    58 }
    59 static inline void ^?{}(FinishAction * this) {}
    60 
    6140struct processor {
    62         struct processorCtx_t * runner;
     41        struct processorCtx_t * ctx;
    6342        cluster * cltr;
    6443        coroutine * current_coroutine;
    6544        thread * current_thread;
    6645        pthread_t kernel_thread;
    67        
    68         signal_once terminated;
    69         volatile bool is_terminated;
    70 
    71         struct FinishAction finish;
     46        simple_lock lock;
     47        volatile bool terminated;
    7248};
    7349
     
    7551void ?{}(processor * this, cluster * cltr);
    7652void ^?{}(processor * this);
     53
     54
     55//-----------------------------------------------------------------------------
     56// Locks
     57
     58void ?{}(simple_lock * this);
     59void ^?{}(simple_lock * this);
     60
     61void lock( simple_lock * );
     62void unlock( simple_lock * );
     63
     64struct pthread_spinlock_guard {
     65        pthread_spinlock_t * lock;
     66};
     67
     68static inline void ?{}( pthread_spinlock_guard * this, pthread_spinlock_t * lock ) {
     69        this->lock = lock;
     70        pthread_spin_lock( this->lock );
     71}
     72
     73static inline void ^?{}( pthread_spinlock_guard * this ) {
     74        pthread_spin_unlock( this->lock );
     75}
     76
     77// //Simple spinlock implementation from
     78// //http://stackoverflow.com/questions/1383363/is-my-spin-lock-implementation-correct-and-optimal
     79// //Not optimal but correct
     80// #define VOL
     81
     82// struct simple_spinlock {
     83//      VOL int lock;
     84// };
     85
     86// extern VOL int __sync_lock_test_and_set( VOL int *, VOL int);
     87// extern void __sync_synchronize();
     88
     89// static inline void lock( simple_spinlock * this ) {
     90//     while (__sync_lock_test_and_set(&this->lock, 1)) {
     91//         // Do nothing. This GCC builtin instruction
     92//         // ensures memory barrier.
     93//     }
     94// }
     95
     96// static inline void unlock( simple_spinlock * this ) {
     97//     __sync_synchronize(); // Memory barrier.
     98//     this->lock = 0;
     99// }
    77100
    78101#endif //KERNEL_H
Note: See TracChangeset for help on using the changeset viewer.