Ignore:
Timestamp:
May 11, 2020, 1:53:29 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
504a7dc
Parents:
b7d6a36 (diff), a7b486b (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' into relaxed_ready

File:
1 edited

Legend:

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

    rb7d6a36 r6a490b2  
    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
     
    11770        // RunThread data
    11871        // Action to do after a thread is ran
    119         struct FinishAction finish;
     72        $thread * destroyer;
    12073
    12174        // Preemption data
     
    12679        bool pending_preemption;
    12780
    128         // Idle lock
    129         __bin_sem_t idleLock;
     81        // Idle lock (kernel semaphore)
     82        __bin_sem_t idle;
    13083
    13184        // Termination
     
    13386        volatile bool do_terminate;
    13487
    135         // Termination synchronisation
     88        // Termination synchronisation (user semaphore)
    13689        semaphore terminated;
    13790
     
    158111static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    159112
    160 static inline [processor *&, processor *& ] __get( processor & this ) {
    161         return this.node.[next, prev];
    162 }
     113static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }
     114
     115//-----------------------------------------------------------------------------
     116// I/O
     117struct __io_data;
     118
     119#define CFA_CLUSTER_IO_POLLER_USER_THREAD 1 << 0
     120// #define CFA_CLUSTER_IO_POLLER_KERNEL_SIDE 1 << 1
    163121
    164122
     
    333291        // List of threads
    334292        __spinlock_t thread_list_lock;
    335         __dllist_t(struct thread_desc) threads;
     293        __dllist_t(struct $thread) threads;
    336294        unsigned int nthreads;
    337295
     
    341299                cluster * prev;
    342300        } node;
     301
     302        struct __io_data * io;
     303
     304        #if !defined(__CFA_NO_STATISTICS__)
     305                bool print_stats;
     306        #endif
    343307};
    344308extern Duration default_preemption();
    345309
    346 void ?{} (cluster & this, const char name[], Duration preemption_rate);
     310void ?{} (cluster & this, const char name[], Duration preemption_rate, int flags);
    347311void ^?{}(cluster & this);
    348312
    349 static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
    350 static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
    351 static inline void ?{} (cluster & this, const char name[])        { this{name, default_preemption()}; }
    352 
    353 static inline [cluster *&, cluster *& ] __get( cluster & this ) {
    354         return this.node.[next, prev];
    355 }
     313static inline void ?{} (cluster & this)                                      { this{"Anonymous Cluster", default_preemption(), 0}; }
     314static inline void ?{} (cluster & this, Duration preemption_rate)            { this{"Anonymous Cluster", preemption_rate, 0}; }
     315static inline void ?{} (cluster & this, const char name[])                   { this{name, default_preemption(), 0}; }
     316static inline void ?{} (cluster & this, int flags)                           { this{"Anonymous Cluster", default_preemption(), flags}; }
     317static inline void ?{} (cluster & this, Duration preemption_rate, int flags) { this{"Anonymous Cluster", preemption_rate, flags}; }
     318static inline void ?{} (cluster & this, const char name[], int flags)        { this{name, default_preemption(), flags}; }
     319
     320static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; }
    356321
    357322static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE
    358323static inline struct cluster   * active_cluster  () { return TL_GET( this_processor )->cltr; }
     324
     325#if !defined(__CFA_NO_STATISTICS__)
     326        static inline void print_stats_at_exit( cluster & this ) {
     327                this.print_stats = true;
     328        }
     329#endif
    359330
    360331// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.