Ignore:
File:
1 edited

Legend:

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

    r92e7631 rd4e68a6  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  4 12:29:26 2020
    13 // Update Count     : 22
     12// Last Modified On : Sat Jun 22 11:39:17 2019
     13// Update Count     : 16
    1414//
    1515
     
    2020#include "invoke.h"
    2121#include "time_t.hfa"
    22 #include "coroutine.hfa"
    2322
    2423extern "C" {
     
    3231        __spinlock_t lock;
    3332        int count;
    34         __queue_t($thread) waiting;
     33        __queue_t(thread_desc) waiting;
    3534};
    3635
     
    3837void ^?{}(semaphore & this);
    3938void   P (semaphore & this);
    40 bool   V (semaphore & this);
     39void   V (semaphore & this);
    4140
    4241
     
    4443// Processor
    4544extern struct cluster * mainCluster;
     45
     46enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };
     47
     48typedef void (*__finish_callback_fptr_t)(void);
     49
     50//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
     51struct 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};
     88static inline void ?{}(FinishAction & this) {
     89        this.action_code = No_Action;
     90        this.thrd = NULL;
     91        this.lock = NULL;
     92}
     93static inline void ^?{}(FinishAction &) {}
    4694
    4795// Processor
     
    67115        // RunThread data
    68116        // Action to do after a thread is ran
    69         $thread * destroyer;
     117        struct FinishAction finish;
    70118
    71119        // Preemption data
     
    76124        bool pending_preemption;
    77125
    78         // Idle lock (kernel semaphore)
    79         __bin_sem_t idle;
     126        // Idle lock
     127        __bin_sem_t idleLock;
    80128
    81129        // Termination
     
    83131        volatile bool do_terminate;
    84132
    85         // Termination synchronisation (user semaphore)
     133        // Termination synchronisation
    86134        semaphore terminated;
    87 
    88         // pthread Stack
    89         void * stack;
    90135
    91136        // Link lists fields
     
    101146};
    102147
    103 void  ?{}(processor & this, const char name[], struct cluster & cltr);
     148void  ?{}(processor & this, const char * name, struct cluster & cltr);
    104149void ^?{}(processor & this);
    105150
    106151static inline void  ?{}(processor & this)                    { this{ "Anonymous Processor", *mainCluster}; }
    107152static inline void  ?{}(processor & this, struct cluster & cltr)    { this{ "Anonymous Processor", cltr}; }
    108 static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    109 
    110 static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }
     153static inline void  ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
     154
     155static inline [processor *&, processor *& ] __get( processor & this ) {
     156        return this.node.[next, prev];
     157}
    111158
    112159//-----------------------------------------------------------------------------
     
    117164
    118165        // Ready queue for threads
    119         __queue_t($thread) ready_queue;
     166        __queue_t(thread_desc) ready_queue;
    120167
    121168        // Name of the cluster
     
    126173
    127174        // List of processors
    128         __spinlock_t idle_lock;
     175        __spinlock_t proc_list_lock;
    129176        __dllist_t(struct processor) procs;
    130177        __dllist_t(struct processor) idles;
     
    133180        // List of threads
    134181        __spinlock_t thread_list_lock;
    135         __dllist_t(struct $thread) threads;
     182        __dllist_t(struct thread_desc) threads;
    136183        unsigned int nthreads;
    137184
     
    144191extern Duration default_preemption();
    145192
    146 void ?{} (cluster & this, const char name[], Duration preemption_rate);
     193void ?{} (cluster & this, const char * name, Duration preemption_rate);
    147194void ^?{}(cluster & this);
    148195
    149196static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
    150197static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
    151 static inline void ?{} (cluster & this, const char name[])        { this{name, default_preemption()}; }
    152 
    153 static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; }
     198static inline void ?{} (cluster & this, const char * name)        { this{name, default_preemption()}; }
     199
     200static inline [cluster *&, cluster *& ] __get( cluster & this ) {
     201        return this.node.[next, prev];
     202}
    154203
    155204static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE
Note: See TracChangeset for help on using the changeset viewer.