source: src/libcfa/concurrency/kernel @ ee897e4b

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

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

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[8118303]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
[75f3522]11// Created On       : Tue Jan 17 12:27:26 2017
[8118303]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
[c84e80a]20#include <stdbool.h>
[8118303]21
[bd98b58]22#include "invoke.h"
23
[8def349]24extern "C" {
25#include <pthread.h>
26}
27
[db6f06a]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
[bd98b58]40//-----------------------------------------------------------------------------
41// Cluster
42struct cluster {
43        simple_thread_list ready_queue;
[db6f06a]44        spinlock lock;
[bd98b58]45};
46
47void ?{}(cluster * this);
48void ^?{}(cluster * this);
49
50//-----------------------------------------------------------------------------
51// Processor
[db6f06a]52enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule };
53struct FinishAction {
54        FinishOpCode action_code;
55        thread * thrd;
56        spinlock * lock;
[8fcbb4c]57};
[db6f06a]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) {}
[8fcbb4c]64
[c84e80a]65struct processor {
[8fcbb4c]66        struct processorCtx_t * runner;
[bd98b58]67        cluster * cltr;
68        coroutine * current_coroutine;
[e15df4c]69        thread * current_thread;
[8def349]70        pthread_t kernel_thread;
[db6f06a]71       
72        signal_once terminated;
73        volatile bool is_terminated;
74
75        struct FinishAction finish;
[c84e80a]76};
77
[8def349]78void ?{}(processor * this);
[bd98b58]79void ?{}(processor * this, cluster * cltr);
[c84e80a]80void ^?{}(processor * this);
81
[8118303]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.