source: src/libcfa/concurrency/kernel @ f5478c8

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f5478c8 was f5478c8, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

  • Property mode set to 100644
File size: 2.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// kernel --
8//
9// Author           : Thierry Delisle
10// Created On       : Tue Jan 17 12:27:26 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sat Jul 22 09:58:39 2017
13// Update Count     : 2
14//
15
16#pragma once
17
18#include <stdbool.h>
19
20#include "invoke.h"
21
22extern "C" {
23#include <pthread.h>
24}
25
26//-----------------------------------------------------------------------------
27// Locks
28struct semaphore {
29        __spinlock_t lock;
30        int count;
31        __queue_t(thread_desc) waiting;
32};
33
34void  ?{}(semaphore & this, int count = 1);
35void ^?{}(semaphore & this);
36void   P (semaphore & this);
37void   V (semaphore & this);
38
39
40//-----------------------------------------------------------------------------
41// Cluster
42struct cluster {
43        // Ready queue locks
44        __spinlock_t ready_queue_lock;
45
46        // Ready queue for threads
47        __queue_t(thread_desc) ready_queue;
48
49        // Preemption rate on this cluster
50        unsigned long long int preemption;
51};
52
53void ?{} (cluster & this);
54void ^?{}(cluster & this);
55
56//-----------------------------------------------------------------------------
57// Processor
58enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
59
60//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
61struct FinishAction {
62        FinishOpCode action_code;
63        thread_desc * thrd;
64        __spinlock_t * lock;
65        __spinlock_t ** locks;
66        unsigned short lock_count;
67        thread_desc ** thrds;
68        unsigned short thrd_count;
69};
70static inline void ?{}(FinishAction & this) {
71        this.action_code = No_Action;
72        this.thrd = NULL;
73        this.lock = NULL;
74}
75static inline void ^?{}(FinishAction & this) {}
76
77// Processor
78// Wrapper around kernel threads
79struct processor {
80        // Main state
81        // Coroutine ctx who does keeps the state of the processor
82        struct processorCtx_t * runner;
83
84        // Cluster from which to get threads
85        cluster * cltr;
86
87        // Handle to pthreads
88        pthread_t kernel_thread;
89
90        // Termination
91        // Set to true to notify the processor should terminate
92        volatile bool do_terminate;
93
94        // Termination synchronisation
95        semaphore terminated;
96
97        // RunThread data
98        // Action to do after a thread is ran
99        struct FinishAction finish;
100
101        // Preemption data
102        // Node which is added in the discrete event simulaiton
103        struct alarm_node_t * preemption_alarm;
104
105        // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
106        bool pending_preemption;
107
108#ifdef __CFA_DEBUG__
109        // Last function to enable preemption on this processor
110        const char * last_enable;
111#endif
112};
113
114void  ?{}(processor & this);
115void  ?{}(processor & this, cluster * cltr);
116void ^?{}(processor & this);
117
118// Local Variables: //
119// mode: c //
120// tab-width: 4 //
121// End: //
Note: See TracBrowser for help on using the repository browser.