source: src/libcfa/concurrency/kernel @ 3edc2df

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 3edc2df was 025278e, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Changed comments to be above fields, to help source control diff readability

  • Property mode set to 100644
File size: 3.1 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
28// Lock the spinlock, spin if already acquired
29void lock      ( spinlock * DEBUG_CTX_PARAM2 );
30
31// Lock the spinlock, yield repeatedly if already acquired
32void lock_yield( spinlock * DEBUG_CTX_PARAM2 );
33
34// Lock the spinlock, return false if already acquired
35bool try_lock  ( spinlock * DEBUG_CTX_PARAM2 );
36
37// Unlock the spinlock
38void unlock    ( spinlock * );
39
40struct semaphore {
41        spinlock lock;
42        int count;
43        __thread_queue_t waiting;
44};
45
46void  ?{}(semaphore & this, int count = 1);
47void ^?{}(semaphore & this);
48void   P (semaphore & this);
49void   V (semaphore & this);
50
51
52//-----------------------------------------------------------------------------
53// Cluster
54struct cluster {
55        // Ready queue locks
56        spinlock ready_queue_lock;
57
58        // Ready queue for threads
59        __thread_queue_t ready_queue;
60
61        // Preemption rate on this cluster
62        unsigned long long int preemption;
63};
64
65void ?{} (cluster & this);
66void ^?{}(cluster & this);
67
68//-----------------------------------------------------------------------------
69// Processor
70enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
71
72//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
73struct FinishAction {
74        FinishOpCode action_code;
75        thread_desc * thrd;
76        spinlock * lock;
77        spinlock ** locks;
78        unsigned short lock_count;
79        thread_desc ** thrds;
80        unsigned short thrd_count;
81};
82static inline void ?{}(FinishAction & this) {
83        this.action_code = No_Action;
84        this.thrd = NULL;
85        this.lock = NULL;
86}
87static inline void ^?{}(FinishAction & this) {}
88
89// Processor
90// Wrapper around kernel threads
91struct processor {
92        // Main state
93        // Coroutine ctx who does keeps the state of the processor
94        struct processorCtx_t * runner;
95
96        // Cluster from which to get threads
97        cluster * cltr;
98
99        // Handle to pthreads
100        pthread_t kernel_thread;
101
102        // Termination
103        // Set to true to notify the processor should terminate
104        volatile bool do_terminate;
105
106        // Termination synchronisation
107        semaphore terminated;
108
109        // RunThread data
110        // Action to do after a thread is ran
111        struct FinishAction finish;
112
113        // Preemption data
114        // Node which is added in the discrete event simulaiton
115        struct alarm_node_t * preemption_alarm;
116
117        // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
118        bool pending_preemption;
119
120#ifdef __CFA_DEBUG__
121        // Last function to enable preemption on this processor
122        char * last_enable;
123#endif
124};
125
126void  ?{}(processor & this);
127void  ?{}(processor & this, cluster * cltr);
128void ^?{}(processor & this);
129
130// Local Variables: //
131// mode: c //
132// tab-width: 4 //
133// End: //
Note: See TracBrowser for help on using the repository browser.