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 6ce9f7c7 was
f07e037,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Basic monitor implementation
|
-
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 THREADS_H |
---|
18 | #define THREADS_H |
---|
19 | |
---|
20 | #include "assert" |
---|
21 | #include "invoke.h" |
---|
22 | |
---|
23 | #include "coroutines" |
---|
24 | |
---|
25 | //----------------------------------------------------------------------------- |
---|
26 | // Coroutine trait |
---|
27 | // Anything that implements this trait can be resumed. |
---|
28 | // Anything that is resumed is a coroutine. |
---|
29 | trait is_thread(dtype T) { |
---|
30 | void main(T* this); |
---|
31 | thread* get_thread(T* this); |
---|
32 | }; |
---|
33 | |
---|
34 | #define DECL_THREAD(X) thread* get_thread(X* this) { return &this->t; } void main(X* this) |
---|
35 | |
---|
36 | forall( dtype T | is_thread(T) ) |
---|
37 | static inline coroutine* get_coroutine(T* this) { |
---|
38 | return &get_thread(this)->c; |
---|
39 | } |
---|
40 | |
---|
41 | static inline coroutine* get_coroutine(thread* this) { |
---|
42 | return &this->c; |
---|
43 | } |
---|
44 | |
---|
45 | thread * this_thread(void); |
---|
46 | |
---|
47 | //----------------------------------------------------------------------------- |
---|
48 | // Ctors and dtors |
---|
49 | void ?{}(thread* this); |
---|
50 | void ^?{}(thread* this); |
---|
51 | |
---|
52 | //----------------------------------------------------------------------------- |
---|
53 | // thread runner |
---|
54 | // Structure that actually start and stop threads |
---|
55 | forall( dtype T | sized(T) | is_thread(T) ) |
---|
56 | struct scoped { |
---|
57 | T handle; |
---|
58 | }; |
---|
59 | |
---|
60 | forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } ) |
---|
61 | void ?{}( scoped(T)* this ); |
---|
62 | |
---|
63 | forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } ) |
---|
64 | void ?{}( scoped(T)* this, P params ); |
---|
65 | |
---|
66 | forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } ) |
---|
67 | void ^?{}( scoped(T)* this ); |
---|
68 | |
---|
69 | void yield(); |
---|
70 | |
---|
71 | #endif //THREADS_H |
---|
72 | |
---|
73 | // Local Variables: // |
---|
74 | // mode: c // |
---|
75 | // tab-width: 4 // |
---|
76 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.