source: src/libcfa/concurrency/kernel @ db6f06a

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

Implemented better condition lock to solve race condition on thread/processor termination

  • Property mode set to 100644
File size: 1.9 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// threads --
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
30// void lock( simple_lock * );
31// void lock( simple_lock *, spinlock * );
32// void unlock( simple_lock * );
33
34void lock( spinlock * );
35void unlock( spinlock * );
36
37void wait( signal_once * );
38void signal( signal_once * );
39
40//-----------------------------------------------------------------------------
41// Cluster
42struct cluster {
43        simple_thread_list ready_queue;
44        spinlock lock;
45};
46
47void ?{}(cluster * this);
48void ^?{}(cluster * this);
49
50//-----------------------------------------------------------------------------
51// Processor
52enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule };
53struct FinishAction {
54        FinishOpCode action_code;
55        thread * thrd;
56        spinlock * lock;
57};
58static inline void ?{}(FinishAction * this) {
59        this->action_code = No_Action;
60        this->thrd = NULL;
61        this->lock = NULL;
62}
63static inline void ^?{}(FinishAction * this) {}
64
65struct processor {
66        struct processorCtx_t * runner;
67        cluster * cltr;
68        coroutine * current_coroutine;
69        thread * current_thread;
70        pthread_t kernel_thread;
71       
72        signal_once terminated;
73        volatile bool is_terminated;
74
75        struct FinishAction finish;
76};
77
78void ?{}(processor * this);
79void ?{}(processor * this, cluster * cltr);
80void ^?{}(processor * this);
81
82#endif //KERNEL_H
83
84// Local Variables: //
85// mode: c //
86// tab-width: 4 //
87// End: //
Note: See TracBrowser for help on using the repository browser.