Ignore:
File:
1 edited

Legend:

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

    r71c8b7e re3fea42  
    1717
    1818#include <stdbool.h>
    19 #include <stdint.h>
    2019
    2120#include "invoke.h"
     
    3332        __spinlock_t lock;
    3433        int count;
    35         __queue_t($thread) waiting;
     34        __queue_t(thread_desc) waiting;
    3635};
    3736
    3837void  ?{}(semaphore & this, int count = 1);
    3938void ^?{}(semaphore & this);
    40 bool   P (semaphore & this);
    41 bool   V (semaphore & this);
    42 bool   V (semaphore & this, unsigned count);
     39void   P (semaphore & this);
     40void   V (semaphore & this);
    4341
    4442
     
    4644// Processor
    4745extern struct cluster * mainCluster;
     46
     47enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };
     48
     49typedef void (*__finish_callback_fptr_t)(void);
     50
     51//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
     52struct FinishAction {
     53        FinishOpCode action_code;
     54        /*
     55        // Union of possible actions
     56        union {
     57                // Option 1 : locks and threads
     58                struct {
     59                        // 1 thread or N thread
     60                        union {
     61                                thread_desc * thrd;
     62                                struct {
     63                                        thread_desc ** thrds;
     64                                        unsigned short thrd_count;
     65                                };
     66                        };
     67                        // 1 lock or N lock
     68                        union {
     69                                __spinlock_t * lock;
     70                                struct {
     71                                        __spinlock_t ** locks;
     72                                        unsigned short lock_count;
     73                                };
     74                        };
     75                };
     76                // Option 2 : action pointer
     77                __finish_callback_fptr_t callback;
     78        };
     79        /*/
     80        thread_desc * thrd;
     81        thread_desc ** thrds;
     82        unsigned short thrd_count;
     83        __spinlock_t * lock;
     84        __spinlock_t ** locks;
     85        unsigned short lock_count;
     86        __finish_callback_fptr_t callback;
     87        //*/
     88};
     89static inline void ?{}(FinishAction & this) {
     90        this.action_code = No_Action;
     91        this.thrd = 0p;
     92        this.lock = 0p;
     93}
     94static inline void ^?{}(FinishAction &) {}
    4895
    4996// Processor
     
    69116        // RunThread data
    70117        // Action to do after a thread is ran
    71         $thread * destroyer;
     118        struct FinishAction finish;
    72119
    73120        // Preemption data
     
    78125        bool pending_preemption;
    79126
    80         // Idle lock (kernel semaphore)
    81         __bin_sem_t idle;
     127        // Idle lock
     128        __bin_sem_t idleLock;
    82129
    83130        // Termination
     
    85132        volatile bool do_terminate;
    86133
    87         // Termination synchronisation (user semaphore)
     134        // Termination synchronisation
    88135        semaphore terminated;
    89136
     
    110157static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    111158
    112 static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }
    113 
    114 //-----------------------------------------------------------------------------
    115 // I/O
    116 struct __io_data;
    117 
    118 #define CFA_CLUSTER_IO_POLLER_USER_THREAD 1 << 0
    119 // #define CFA_CLUSTER_IO_POLLER_KERNEL_SIDE 1 << 1
     159static inline [processor *&, processor *& ] __get( processor & this ) {
     160        return this.node.[next, prev];
     161}
    120162
    121163//-----------------------------------------------------------------------------
     
    126168
    127169        // Ready queue for threads
    128         __queue_t($thread) ready_queue;
     170        __queue_t(thread_desc) ready_queue;
    129171
    130172        // Name of the cluster
     
    135177
    136178        // List of processors
    137         __spinlock_t idle_lock;
     179        __spinlock_t proc_list_lock;
    138180        __dllist_t(struct processor) procs;
    139181        __dllist_t(struct processor) idles;
     
    142184        // List of threads
    143185        __spinlock_t thread_list_lock;
    144         __dllist_t(struct $thread) threads;
     186        __dllist_t(struct thread_desc) threads;
    145187        unsigned int nthreads;
    146188
     
    150192                cluster * prev;
    151193        } node;
    152 
    153         struct __io_data * io;
    154 
    155         #if !defined(__CFA_NO_STATISTICS__)
    156                 bool print_stats;
    157         #endif
    158194};
    159195extern Duration default_preemption();
    160196
    161 void ?{} (cluster & this, const char name[], Duration preemption_rate, int flags);
     197void ?{} (cluster & this, const char name[], Duration preemption_rate);
    162198void ^?{}(cluster & this);
    163199
    164 static inline void ?{} (cluster & this)                                      { this{"Anonymous Cluster", default_preemption(), 0}; }
    165 static inline void ?{} (cluster & this, Duration preemption_rate)            { this{"Anonymous Cluster", preemption_rate, 0}; }
    166 static inline void ?{} (cluster & this, const char name[])                   { this{name, default_preemption(), 0}; }
    167 static inline void ?{} (cluster & this, int flags)                           { this{"Anonymous Cluster", default_preemption(), flags}; }
    168 static inline void ?{} (cluster & this, Duration preemption_rate, int flags) { this{"Anonymous Cluster", preemption_rate, flags}; }
    169 static inline void ?{} (cluster & this, const char name[], int flags)        { this{name, default_preemption(), flags}; }
    170 
    171 static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; }
     200static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
     201static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
     202static inline void ?{} (cluster & this, const char name[])        { this{name, default_preemption()}; }
     203
     204static inline [cluster *&, cluster *& ] __get( cluster & this ) {
     205        return this.node.[next, prev];
     206}
    172207
    173208static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE
    174209static inline struct cluster   * active_cluster  () { return TL_GET( this_processor )->cltr; }
    175 
    176 #if !defined(__CFA_NO_STATISTICS__)
    177         static inline void print_stats_at_exit( cluster & this ) {
    178                 this.print_stats = true;
    179         }
    180 #endif
    181210
    182211// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.