[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 | //
|
---|
[78b3f52] | 8 | // threads --
|
---|
[0e76cf4f] | 9 | //
|
---|
[78b3f52] | 10 | // Author : Thierry Delisle
|
---|
[6a3d2e7] | 11 | // Created On : Tue Jan 17 12:27:26 2016
|
---|
[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 |
|
---|
[8118303] | 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 /*| sized(T)*/) {
|
---|
[7fbe450] | 30 | void main(T* this);
|
---|
[8118303] | 31 | thread_h* get_thread(T* this);
|
---|
| 32 | /*void ?{}(T*);
|
---|
| 33 | void ^?{}(T*);*/
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | forall(otype T | is_thread(T) )
|
---|
| 37 | static inline coroutine* get_coroutine(T* this) {
|
---|
| 38 | return &get_thread(this)->c;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[c84e80a] | 41 | static inline coroutine* get_coroutine(thread_h* this) {
|
---|
| 42 | return &this->c;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[8118303] | 45 | //-----------------------------------------------------------------------------
|
---|
| 46 | // Ctors and dtors
|
---|
| 47 | void ?{}(thread_h* this);
|
---|
| 48 | void ^?{}(thread_h* this);
|
---|
| 49 |
|
---|
| 50 | //-----------------------------------------------------------------------------
|
---|
| 51 | // thread runner
|
---|
| 52 | // Structure that actually start and stop threads
|
---|
| 53 | forall(otype T | is_thread(T) )
|
---|
| 54 | struct thread {
|
---|
| 55 | T handle;
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | forall(otype T | is_thread(T) )
|
---|
| 59 | void ?{}( thread(T)* this );
|
---|
| 60 |
|
---|
| 61 | forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
|
---|
| 62 | void ?{}( thread(T)* this, P params );
|
---|
| 63 |
|
---|
| 64 | forall(otype T | is_thread(T) )
|
---|
| 65 | void ^?{}( thread(T)* this );
|
---|
| 66 |
|
---|
| 67 | //-----------------------------------------------------------------------------
|
---|
| 68 | // PRIVATE exposed because of inline
|
---|
[596f987b] | 69 |
|
---|
[17e5e2b] | 70 | #endif //THREADS_H
|
---|
| 71 |
|
---|
[78b3f52] | 72 | // Local Variables: //
|
---|
| 73 | // mode: c //
|
---|
| 74 | // tab-width: 4 //
|
---|
| 75 | // End: //
|
---|