1 | #include <stdbool.h>
|
---|
2 | #include <stdint.h>
|
---|
3 |
|
---|
4 | #ifdef __CFORALL__
|
---|
5 | extern "C" {
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #if ! defined(__CFA_INVOKE_PRIVATE__)
|
---|
9 | #ifndef _INVOKE_H_
|
---|
10 | #define _INVOKE_H_
|
---|
11 |
|
---|
12 | #define unlikely(x) __builtin_expect(!!(x), 0)
|
---|
13 | #define SCHEDULER_CAPACITY 10
|
---|
14 |
|
---|
15 | struct simple_thread_list {
|
---|
16 | struct thread_h * head;
|
---|
17 | struct thread_h ** tail;
|
---|
18 | };
|
---|
19 |
|
---|
20 | #ifdef __CFORALL__
|
---|
21 | extern "Cforall" {
|
---|
22 | void ?{}( struct simple_thread_list * );
|
---|
23 | void append( struct simple_thread_list *, struct thread_h * );
|
---|
24 | struct thread_h * pop_head( struct simple_thread_list * );
|
---|
25 | }
|
---|
26 | #endif
|
---|
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 | enum coroutine_state { Start, Inactive, Active, Halt, Primed };
|
---|
39 |
|
---|
40 | struct coroutine {
|
---|
41 | struct coStack_t stack;
|
---|
42 | const char *name; // textual name for coroutine/task, initialized by uC++ generated code
|
---|
43 | int errno_; // copy of global UNIX variable errno
|
---|
44 | enum coroutine_state state; // current execution status for coroutine
|
---|
45 | bool notHalted; // indicate if execuation state is not halted
|
---|
46 |
|
---|
47 | struct coroutine *starter; // first coroutine to resume this one
|
---|
48 | struct coroutine *last; // last coroutine to resume this one
|
---|
49 | };
|
---|
50 |
|
---|
51 | struct simple_lock {
|
---|
52 | struct simple_thread_list blocked;
|
---|
53 | };
|
---|
54 |
|
---|
55 | struct thread_h {
|
---|
56 | struct coroutine c;
|
---|
57 | struct simple_lock lock;
|
---|
58 | struct thread_h * next;
|
---|
59 | };
|
---|
60 |
|
---|
61 | #endif //_INVOKE_H_
|
---|
62 | #else //! defined(__CFA_INVOKE_PRIVATE__)
|
---|
63 | #ifndef _INVOKE_PRIVATE_H_
|
---|
64 | #define _INVOKE_PRIVATE_H_
|
---|
65 |
|
---|
66 | struct machine_context_t {
|
---|
67 | void *SP;
|
---|
68 | void *FP;
|
---|
69 | void *PC;
|
---|
70 | };
|
---|
71 |
|
---|
72 | // assembler routines that performs the context switch
|
---|
73 | extern void CtxInvokeStub( void );
|
---|
74 | void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
|
---|
75 | void CtxGet( void * this ) asm ("CtxGet");
|
---|
76 |
|
---|
77 | #endif //_INVOKE_PRIVATE_H_
|
---|
78 | #endif //! defined(__CFA_INVOKE_PRIVATE__)
|
---|
79 | #ifdef __CFORALL__
|
---|
80 | }
|
---|
81 | #endif
|
---|