source: src/libcfa/concurrency/kernel@ ad6343e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since ad6343e was 8def349, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

cfa now supports processors which represent kernel threads, allowing basic parallelism

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