Ignore:
Timestamp:
Jan 27, 2017, 3:27:34 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, resolv-new, with_gc
Children:
c0aa336
Parents:
6acb935 (diff), 0a86a30 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel

    r6acb935 ra362f97  
    2020#include <stdbool.h>
    2121
     22#include "invoke.h"
     23
     24extern "C" {
     25#include <pthread.h>
     26}
     27
     28//-----------------------------------------------------------------------------
     29// Cluster
     30struct cluster {
     31        simple_thread_list ready_queue;
     32        pthread_spinlock_t lock;
     33};
     34
     35void ?{}(cluster * this);
     36void ^?{}(cluster * this);
     37
     38//-----------------------------------------------------------------------------
     39// Processor
    2240struct processor {
    23         struct proc_coroutine * cor;
    24         unsigned int thread_index;
    25         unsigned int thread_count;
    26         struct thread_h * threads[10];
    27         bool terminated;
     41        struct processorCtx_t * ctx;
     42        cluster * cltr;
     43        coroutine * current_coroutine;
     44        thread * current_thread;
     45        pthread_t kernel_thread;
     46        simple_lock lock;
     47        volatile bool terminated;
    2848};
    2949
    3050void ?{}(processor * this);
     51void ?{}(processor * this, cluster * cltr);
    3152void ^?{}(processor * this);
    3253
    33 void scheduler_add( struct thread_h * thrd );
    34 void scheduler_remove( struct thread_h * thrd );
    35 void kernel_run( void );
     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// }
    36100
    37101#endif //KERNEL_H
Note: See TracChangeset for help on using the changeset viewer.