Ignore:
File:
1 edited

Legend:

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

    re3fea42 r71c8b7e  
    1717
    1818#include <stdbool.h>
     19#include <stdint.h>
    1920
    2021#include "invoke.h"
     
    3233        __spinlock_t lock;
    3334        int count;
    34         __queue_t(thread_desc) waiting;
     35        __queue_t($thread) waiting;
    3536};
    3637
    3738void  ?{}(semaphore & this, int count = 1);
    3839void ^?{}(semaphore & this);
    39 void   P (semaphore & this);
    40 void   V (semaphore & this);
     40bool   P (semaphore & this);
     41bool   V (semaphore & this);
     42bool   V (semaphore & this, unsigned count);
    4143
    4244
     
    4446// Processor
    4547extern struct cluster * mainCluster;
    46 
    47 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };
    48 
    49 typedef void (*__finish_callback_fptr_t)(void);
    50 
    51 //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
    52 struct 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 };
    89 static inline void ?{}(FinishAction & this) {
    90         this.action_code = No_Action;
    91         this.thrd = 0p;
    92         this.lock = 0p;
    93 }
    94 static inline void ^?{}(FinishAction &) {}
    9548
    9649// Processor
     
    11669        // RunThread data
    11770        // Action to do after a thread is ran
    118         struct FinishAction finish;
     71        $thread * destroyer;
    11972
    12073        // Preemption data
     
    12578        bool pending_preemption;
    12679
    127         // Idle lock
    128         __bin_sem_t idleLock;
     80        // Idle lock (kernel semaphore)
     81        __bin_sem_t idle;
    12982
    13083        // Termination
     
    13285        volatile bool do_terminate;
    13386
    134         // Termination synchronisation
     87        // Termination synchronisation (user semaphore)
    13588        semaphore terminated;
    13689
     
    157110static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    158111
    159 static inline [processor *&, processor *& ] __get( processor & this ) {
    160         return this.node.[next, prev];
    161 }
     112static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }
     113
     114//-----------------------------------------------------------------------------
     115// I/O
     116struct __io_data;
     117
     118#define CFA_CLUSTER_IO_POLLER_USER_THREAD 1 << 0
     119// #define CFA_CLUSTER_IO_POLLER_KERNEL_SIDE 1 << 1
    162120
    163121//-----------------------------------------------------------------------------
     
    168126
    169127        // Ready queue for threads
    170         __queue_t(thread_desc) ready_queue;
     128        __queue_t($thread) ready_queue;
    171129
    172130        // Name of the cluster
     
    177135
    178136        // List of processors
    179         __spinlock_t proc_list_lock;
     137        __spinlock_t idle_lock;
    180138        __dllist_t(struct processor) procs;
    181139        __dllist_t(struct processor) idles;
     
    184142        // List of threads
    185143        __spinlock_t thread_list_lock;
    186         __dllist_t(struct thread_desc) threads;
     144        __dllist_t(struct $thread) threads;
    187145        unsigned int nthreads;
    188146
     
    192150                cluster * prev;
    193151        } node;
     152
     153        struct __io_data * io;
     154
     155        #if !defined(__CFA_NO_STATISTICS__)
     156                bool print_stats;
     157        #endif
    194158};
    195159extern Duration default_preemption();
    196160
    197 void ?{} (cluster & this, const char name[], Duration preemption_rate);
     161void ?{} (cluster & this, const char name[], Duration preemption_rate, int flags);
    198162void ^?{}(cluster & this);
    199163
    200 static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
    201 static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
    202 static inline void ?{} (cluster & this, const char name[])        { this{name, default_preemption()}; }
     164static inline void ?{} (cluster & this)                                      { this{"Anonymous Cluster", default_preemption(), 0}; }
     165static inline void ?{} (cluster & this, Duration preemption_rate)            { this{"Anonymous Cluster", preemption_rate, 0}; }
     166static inline void ?{} (cluster & this, const char name[])                   { this{name, default_preemption(), 0}; }
     167static inline void ?{} (cluster & this, int flags)                           { this{"Anonymous Cluster", default_preemption(), flags}; }
     168static inline void ?{} (cluster & this, Duration preemption_rate, int flags) { this{"Anonymous Cluster", preemption_rate, flags}; }
     169static inline void ?{} (cluster & this, const char name[], int flags)        { this{name, default_preemption(), flags}; }
    203170
    204 static inline [cluster *&, cluster *& ] __get( cluster & this ) {
    205         return this.node.[next, prev];
    206 }
     171static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; }
    207172
    208173static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE
    209174static 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
    210181
    211182// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.