source:
src/libcfa/concurrency/thread@
7c70089
Last change on this file since 7c70089 was 17af7d1, checked in by , 9 years ago | |
---|---|
|
|
File size: 1.9 KB |
Rev | Line | |
---|---|---|
[78b3f52] | 1 | // -*- Mode: CFA -*- |
[0e76cf4f] | 2 | // |
[78b3f52] | 3 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
[0e76cf4f] | 4 | // |
5 | // The contents of this file are covered under the licence agreement in the | |
6 | // file "LICENCE" distributed with Cforall. | |
7 | // | |
[75a17f1] | 8 | // thread -- |
[0e76cf4f] | 9 | // |
[78b3f52] | 10 | // Author : Thierry Delisle |
[f07e037] | 11 | // Created On : Tue Jan 17 12:27:26 2017 |
[78b3f52] | 12 | // Last Modified By : Thierry Delisle |
[6a3d2e7] | 13 | // Last Modified On : -- |
[78b3f52] | 14 | // Update Count : 0 |
[0e76cf4f] | 15 | // |
16 | ||
[17e5e2b] | 17 | #ifndef THREADS_H |
18 | #define THREADS_H | |
[0e76cf4f] | 19 | |
[8118303] | 20 | #include "assert" |
21 | #include "invoke.h" | |
[78b3f52] | 22 | |
[75a17f1] | 23 | #include "coroutine" |
[8118303] | 24 | |
25 | //----------------------------------------------------------------------------- | |
26 | // Coroutine trait | |
27 | // Anything that implements this trait can be resumed. | |
28 | // Anything that is resumed is a coroutine. | |
[0c92c9f] | 29 | trait is_thread(dtype T) { |
[9f1695b] | 30 | void ^?{}(T* this); |
[7fbe450] | 31 | void main(T* this); |
[348006f] | 32 | thread_desc* get_thread(T* this); |
[8118303] | 33 | }; |
34 | ||
[17af7d1] | 35 | #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->__thrd; } void main(X* this) |
[8f49a54] | 36 | |
[0c92c9f] | 37 | forall( dtype T | is_thread(T) ) |
[c3acb841] | 38 | static inline coroutine_desc* get_coroutine(T* this) { |
[17af7d1] | 39 | return &get_thread(this)->cor; |
[8118303] | 40 | } |
41 | ||
[348006f] | 42 | static inline coroutine_desc* get_coroutine(thread_desc* this) { |
[17af7d1] | 43 | return &this->cor; |
[c84e80a] | 44 | } |
45 | ||
[348006f] | 46 | thread_desc * this_thread(void); |
[bd98b58] | 47 | |
[8118303] | 48 | //----------------------------------------------------------------------------- |
49 | // Ctors and dtors | |
[348006f] | 50 | void ?{}(thread_desc* this); |
51 | void ^?{}(thread_desc* this); | |
[8118303] | 52 | |
53 | //----------------------------------------------------------------------------- | |
54 | // thread runner | |
55 | // Structure that actually start and stop threads | |
[8def349] | 56 | forall( dtype T | sized(T) | is_thread(T) ) |
[e15df4c] | 57 | struct scoped { |
[8118303] | 58 | T handle; |
59 | }; | |
60 | ||
[8def349] | 61 | forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } ) |
[e15df4c] | 62 | void ?{}( scoped(T)* this ); |
[8118303] | 63 | |
[8def349] | 64 | forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } ) |
[e15df4c] | 65 | void ?{}( scoped(T)* this, P params ); |
[8118303] | 66 | |
[9f1695b] | 67 | forall( dtype T | sized(T) | is_thread(T) ) |
[e15df4c] | 68 | void ^?{}( scoped(T)* this ); |
[8118303] | 69 | |
[bd98b58] | 70 | void yield(); |
[596f987b] | 71 | |
[17e5e2b] | 72 | #endif //THREADS_H |
73 | ||
[78b3f52] | 74 | // Local Variables: // |
75 | // mode: c // | |
76 | // tab-width: 4 // | |
77 | // End: // |
Note:
See TracBrowser
for help on using the repository browser.