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 fa66f4e was
78b3f52,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Ugly but working coroutines
|
-
Property mode set to
100644
|
File size:
2.0 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 | // |
---|
[78b3f52] | 8 | // threads -- |
---|
[0e76cf4f] | 9 | // |
---|
[78b3f52] | 10 | // Author : Thierry Delisle |
---|
| 11 | // Created On : Mon Nov 28 12:27:26 2016 |
---|
| 12 | // Last Modified By : Thierry Delisle |
---|
| 13 | // Last Modified On : Mon Nov 28 12:27:26 2016 |
---|
| 14 | // Update Count : 0 |
---|
[0e76cf4f] | 15 | // |
---|
| 16 | |
---|
| 17 | #ifndef __THREADS_H__ |
---|
| 18 | #define __THREADS_H__ |
---|
| 19 | |
---|
[9129a84] | 20 | #include <stdbool.h> |
---|
[0e76cf4f] | 21 | |
---|
[78b3f52] | 22 | extern "C" { |
---|
| 23 | struct coVtable { |
---|
| 24 | void (*main)(void*); |
---|
| 25 | struct coroutine* (*this_coroutine)(void*); |
---|
| 26 | }; |
---|
| 27 | |
---|
| 28 | struct coStack_t { |
---|
| 29 | unsigned int size; // size of stack |
---|
| 30 | void *storage; // pointer to stack |
---|
| 31 | void *limit; // stack grows towards stack limit |
---|
| 32 | void *base; // base of stack |
---|
| 33 | void *context; // address of cfa_context_t |
---|
| 34 | void *top; // address of top of storage |
---|
| 35 | bool userStack; |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | enum coroutine_state { Start, Inactive, Active, Halt }; |
---|
| 40 | |
---|
| 41 | struct coroutine { |
---|
| 42 | coStack_t stack; |
---|
| 43 | const char *name; // textual name for coroutine/task, initialized by uC++ generated code |
---|
| 44 | int errno_; // copy of global UNIX variable errno |
---|
| 45 | coroutine_state state; // current execution status for coroutine |
---|
| 46 | bool notHalted; // indicate if execuation state is not halted |
---|
| 47 | |
---|
| 48 | coroutine *starter; // first coroutine to resume this one |
---|
| 49 | coroutine *last; // last coroutine to resume this one |
---|
| 50 | }; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void ?{}(coStack_t* this); |
---|
[0e76cf4f] | 54 | |
---|
[9129a84] | 55 | void ?{}(coroutine* this); |
---|
| 56 | |
---|
[0e76cf4f] | 57 | trait coroutine_t(dtype T) { |
---|
| 58 | coroutine* this_coroutine(T* this); |
---|
[78b3f52] | 59 | void co_main(T* this); |
---|
| 60 | coVtable* vtable(T* this); |
---|
[0e76cf4f] | 61 | }; |
---|
| 62 | |
---|
[78b3f52] | 63 | forall(dtype T | coroutine_t(T)) |
---|
| 64 | void start(T* cor); |
---|
| 65 | |
---|
[9129a84] | 66 | void suspend(void); |
---|
[0e76cf4f] | 67 | |
---|
| 68 | forall(dtype T | coroutine_t(T)) |
---|
| 69 | void resume(T* cor); |
---|
| 70 | |
---|
| 71 | #endif //__THREADS_H__ |
---|
[78b3f52] | 72 | |
---|
| 73 | // Local Variables: // |
---|
| 74 | // mode: c // |
---|
| 75 | // tab-width: 4 // |
---|
| 76 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.