Ignore:
File:
1 edited

Legend:

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

    rd4e68a6 r92e7631  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 22 11:39:17 2019
    13 // Update Count     : 16
     12// Last Modified On : Tue Feb  4 12:29:26 2020
     13// Update Count     : 22
    1414//
    1515
     
    2020#include "invoke.h"
    2121#include "time_t.hfa"
     22#include "coroutine.hfa"
    2223
    2324extern "C" {
     
    3132        __spinlock_t lock;
    3233        int count;
    33         __queue_t(thread_desc) waiting;
     34        __queue_t($thread) waiting;
    3435};
    3536
     
    3738void ^?{}(semaphore & this);
    3839void   P (semaphore & this);
    39 void   V (semaphore & this);
     40bool   V (semaphore & this);
    4041
    4142
     
    4344// Processor
    4445extern struct cluster * mainCluster;
    45 
    46 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };
    47 
    48 typedef void (*__finish_callback_fptr_t)(void);
    49 
    50 //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
    51 struct FinishAction {
    52         FinishOpCode action_code;
    53         /*
    54         // Union of possible actions
    55         union {
    56                 // Option 1 : locks and threads
    57                 struct {
    58                         // 1 thread or N thread
    59                         union {
    60                                 thread_desc * thrd;
    61                                 struct {
    62                                         thread_desc ** thrds;
    63                                         unsigned short thrd_count;
    64                                 };
    65                         };
    66                         // 1 lock or N lock
    67                         union {
    68                                 __spinlock_t * lock;
    69                                 struct {
    70                                         __spinlock_t ** locks;
    71                                         unsigned short lock_count;
    72                                 };
    73                         };
    74                 };
    75                 // Option 2 : action pointer
    76                 __finish_callback_fptr_t callback;
    77         };
    78         /*/
    79         thread_desc * thrd;
    80         thread_desc ** thrds;
    81         unsigned short thrd_count;
    82         __spinlock_t * lock;
    83         __spinlock_t ** locks;
    84         unsigned short lock_count;
    85         __finish_callback_fptr_t callback;
    86         //*/
    87 };
    88 static inline void ?{}(FinishAction & this) {
    89         this.action_code = No_Action;
    90         this.thrd = NULL;
    91         this.lock = NULL;
    92 }
    93 static inline void ^?{}(FinishAction &) {}
    9446
    9547// Processor
     
    11567        // RunThread data
    11668        // Action to do after a thread is ran
    117         struct FinishAction finish;
     69        $thread * destroyer;
    11870
    11971        // Preemption data
     
    12476        bool pending_preemption;
    12577
    126         // Idle lock
    127         __bin_sem_t idleLock;
     78        // Idle lock (kernel semaphore)
     79        __bin_sem_t idle;
    12880
    12981        // Termination
     
    13183        volatile bool do_terminate;
    13284
    133         // Termination synchronisation
     85        // Termination synchronisation (user semaphore)
    13486        semaphore terminated;
     87
     88        // pthread Stack
     89        void * stack;
    13590
    13691        // Link lists fields
     
    146101};
    147102
    148 void  ?{}(processor & this, const char * name, struct cluster & cltr);
     103void  ?{}(processor & this, const char name[], struct cluster & cltr);
    149104void ^?{}(processor & this);
    150105
    151106static inline void  ?{}(processor & this)                    { this{ "Anonymous Processor", *mainCluster}; }
    152107static inline void  ?{}(processor & this, struct cluster & cltr)    { this{ "Anonymous Processor", cltr}; }
    153 static inline void  ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
     108static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    154109
    155 static inline [processor *&, processor *& ] __get( processor & this ) {
    156         return this.node.[next, prev];
    157 }
     110static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }
    158111
    159112//-----------------------------------------------------------------------------
     
    164117
    165118        // Ready queue for threads
    166         __queue_t(thread_desc) ready_queue;
     119        __queue_t($thread) ready_queue;
    167120
    168121        // Name of the cluster
     
    173126
    174127        // List of processors
    175         __spinlock_t proc_list_lock;
     128        __spinlock_t idle_lock;
    176129        __dllist_t(struct processor) procs;
    177130        __dllist_t(struct processor) idles;
     
    180133        // List of threads
    181134        __spinlock_t thread_list_lock;
    182         __dllist_t(struct thread_desc) threads;
     135        __dllist_t(struct $thread) threads;
    183136        unsigned int nthreads;
    184137
     
    191144extern Duration default_preemption();
    192145
    193 void ?{} (cluster & this, const char * name, Duration preemption_rate);
     146void ?{} (cluster & this, const char name[], Duration preemption_rate);
    194147void ^?{}(cluster & this);
    195148
    196149static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
    197150static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
    198 static inline void ?{} (cluster & this, const char * name)        { this{name, default_preemption()}; }
     151static inline void ?{} (cluster & this, const char name[])        { this{name, default_preemption()}; }
    199152
    200 static inline [cluster *&, cluster *& ] __get( cluster & this ) {
    201         return this.node.[next, prev];
    202 }
     153static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; }
    203154
    204155static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE
Note: See TracChangeset for help on using the changeset viewer.