source: src/libcfa/concurrency/kernel @ 1c273d0

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 1c273d0 was 1c273d0, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

preemption works for threads

  • Property mode set to 100644
File size: 2.4 KB
Line 
1//                              -*- Mode: CFA -*-
2//
3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
7//
8// kernel --
9//
10// Author           : Thierry Delisle
11// Created On       : Tue Jan 17 12:27:26 2017
12// Last Modified By : Thierry Delisle
13// Last Modified On : --
14// Update Count     : 0
15//
16
17#ifndef KERNEL_H
18#define KERNEL_H
19
20#include <stdbool.h>
21
22#include "invoke.h"
23
24extern "C" {
25#include <pthread.h>
26}
27
28//-----------------------------------------------------------------------------
29// Locks
30bool try_lock( spinlock *
31        #ifdef __CFA_DEBUG__
32                , const char * caller
33        #endif
34);
35
36void lock( spinlock *
37        #ifdef __CFA_DEBUG__
38                , const char * caller
39        #endif
40);
41
42void unlock( spinlock * );
43
44struct signal_once {
45        volatile bool cond;
46        struct spinlock lock;
47        struct __thread_queue_t blocked;
48};
49
50void ?{}(signal_once * this);
51void ^?{}(signal_once * this);
52
53void wait( signal_once * );
54void signal( signal_once * );
55
56//-----------------------------------------------------------------------------
57// Cluster
58struct cluster {
59        __thread_queue_t ready_queue;
60        spinlock lock;
61};
62
63void ?{}(cluster * this);
64void ^?{}(cluster * this);
65
66//-----------------------------------------------------------------------------
67// Processor
68enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
69
70//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
71struct FinishAction {
72        FinishOpCode action_code;
73        thread_desc * thrd;
74        spinlock * lock;
75        spinlock ** locks;
76        unsigned short lock_count;
77        thread_desc ** thrds;
78        unsigned short thrd_count;
79};
80static inline void ?{}(FinishAction * this) {
81        this->action_code = No_Action;
82        this->thrd = NULL;
83        this->lock = NULL;
84}
85static inline void ^?{}(FinishAction * this) {}
86
87struct processor {
88        struct processorCtx_t * runner;
89        cluster * cltr;
90        pthread_t kernel_thread;
91       
92        signal_once terminated;
93        volatile bool is_terminated;
94
95        struct FinishAction finish;
96
97        struct alarm_node_t * preemption_alarm;
98        unsigned int preemption;
99
100        bool pending_preemption;
101
102        char * last_enable;
103};
104
105void ?{}(processor * this);
106void ?{}(processor * this, cluster * cltr);
107void ^?{}(processor * this);
108
109#endif //KERNEL_H
110
111// Local Variables: //
112// mode: CFA //
113// tab-width: 6 //
114// End: //
Note: See TracBrowser for help on using the repository browser.