source: src/libcfa/concurrency/kernel @ 8fcbb4c

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

removed pthread_spinlock_t and fixed race condition in yield

  • Property mode set to 100644
File size: 2.5 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 2016
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// Cluster
30struct cluster {
31        simple_thread_list ready_queue;
32        // pthread_spinlock_t lock;
33};
34
35void ?{}(cluster * this);
36void ^?{}(cluster * this);
37
38//-----------------------------------------------------------------------------
39// Processor
40enum ProcessorAction {
41        Reschedule,
42        NoAction
43};
44
45struct processor {
46        struct processorCtx_t * runner;
47        cluster * cltr;
48        coroutine * current_coroutine;
49        thread * current_thread;
50        pthread_t kernel_thread;
51        simple_lock lock;
52        volatile bool terminated;
53        ProcessorAction thread_action;
54};
55
56void ?{}(processor * this);
57void ?{}(processor * this, cluster * cltr);
58void ^?{}(processor * this);
59
60
61//-----------------------------------------------------------------------------
62// Locks
63
64void ?{}(simple_lock * this);
65void ^?{}(simple_lock * this);
66
67void lock( simple_lock * );
68void unlock( simple_lock * );
69
70struct pthread_spinlock_guard {
71        pthread_spinlock_t * lock;
72};
73
74static inline void ?{}( pthread_spinlock_guard * this, pthread_spinlock_t * lock ) {
75        this->lock = lock;
76        pthread_spin_lock( this->lock );
77}
78
79static inline void ^?{}( pthread_spinlock_guard * this ) {
80        pthread_spin_unlock( this->lock );
81}
82
83// //Simple spinlock implementation from
84// //http://stackoverflow.com/questions/1383363/is-my-spin-lock-implementation-correct-and-optimal
85// //Not optimal but correct
86// #define VOL
87
88// struct simple_spinlock {
89//      VOL int lock;
90// };
91
92// extern VOL int __sync_lock_test_and_set( VOL int *, VOL int);
93// extern void __sync_synchronize();
94
95// static inline void lock( simple_spinlock * this ) {
96//     while (__sync_lock_test_and_set(&this->lock, 1)) {
97//         // Do nothing. This GCC builtin instruction
98//         // ensures memory barrier.
99//     }
100// }
101
102// static inline void unlock( simple_spinlock * this ) {
103//     __sync_synchronize(); // Memory barrier.
104//     this->lock = 0;
105// }
106
107#endif //KERNEL_H
108
109// Local Variables: //
110// mode: c //
111// tab-width: 4 //
112// End: //
Note: See TracBrowser for help on using the repository browser.