… | |
… | |
71 | * |
71 | * |
72 | * Microsoft's highly proprietary platform doesn't support sigaltstack, and |
72 | * Microsoft's highly proprietary platform doesn't support sigaltstack, and |
73 | * this automatically selects a suitable workaround for this platform. |
73 | * this automatically selects a suitable workaround for this platform. |
74 | * (untested) |
74 | * (untested) |
75 | * |
75 | * |
|
|
76 | * -DCORO_IRIX |
|
|
77 | * |
|
|
78 | * SGI's version of Microsoft's NT ;) |
|
|
79 | * |
76 | * If you define neither of these symbols, coro.h will try to autodetect |
80 | * If you define neither of these symbols, coro.h will try to autodetect |
77 | * the model. This currently works for CORO_LOOSE only. For the other |
81 | * the model. This currently works for CORO_LOOSE only. For the other |
78 | * alternatives you should check (e.g. using autoconf) and define the |
82 | * alternatives you should check (e.g. using autoconf) and define the |
79 | * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK. |
83 | * following symbols: HAVE_UCONTEXT_H / HAVE_SETJMP_H / HAVE_SIGALTSTACK. |
80 | */ |
84 | */ |
81 | |
85 | |
82 | /* |
86 | /* |
83 | * This is the type for the top function of a new coroutine. |
87 | * This is the type for the initialization function of a new coroutine. |
84 | */ |
88 | */ |
85 | typedef void (*coro_func)(void *); |
89 | typedef void (*coro_func)(void *); |
86 | |
|
|
87 | |
90 | |
88 | /* |
91 | /* |
89 | * A coroutine state is saved in the following structure. Treat it as a |
92 | * A coroutine state is saved in the following structure. Treat it as a |
90 | * opaque type. errno and sigmask might be saved, but don't rely on it, |
93 | * opaque type. errno and sigmask might be saved, but don't rely on it, |
91 | * implement your own switching primitive. |
94 | * implement your own switching primitive. |
… | |
… | |
113 | |
116 | |
114 | /* |
117 | /* |
115 | * That was it. No other user-visible functions are implemented here. |
118 | * That was it. No other user-visible functions are implemented here. |
116 | */ |
119 | */ |
117 | |
120 | |
|
|
121 | /*****************************************************************************/ |
|
|
122 | |
118 | #if !defined(CORO_LOOSE) && !defined(CORO_UCONTEXT) \ |
123 | #if !defined(CORO_LOOSE) && !defined(CORO_UCONTEXT) \ |
119 | && !defined(CORO_SJLJ) && !defined(CORO_LINUX) |
124 | && !defined(CORO_SJLJ) && !defined(CORO_LINUX) \ |
|
|
125 | && !defined(CORO_IRIX) |
120 | # if defined(WINDOWS) |
126 | # if defined(WINDOWS) |
121 | # define CORO_LOOSE 1 /* you don't win with windoze */ |
127 | # define CORO_LOOSE 1 /* you don't win with windoze */ |
122 | # elif defined(__linux) && defined(__x86) |
128 | # elif defined(__linux) && defined(__x86) |
123 | # elif defined(HAVE_UCONTEXT_H) |
129 | # elif defined(HAVE_UCONTEXT_H) |
124 | # define CORO_UCONTEXT 1 |
130 | # define CORO_UCONTEXT 1 |
… | |
… | |
127 | # else |
133 | # else |
128 | error unknown or unsupported architecture |
134 | error unknown or unsupported architecture |
129 | # endif |
135 | # endif |
130 | #endif |
136 | #endif |
131 | |
137 | |
|
|
138 | /*****************************************************************************/ |
|
|
139 | |
132 | #if CORO_UCONTEXT |
140 | #if CORO_UCONTEXT |
133 | |
141 | |
134 | #include <ucontext.h> |
142 | #include <ucontext.h> |
135 | |
143 | |
136 | struct coro_context { |
144 | struct coro_context { |
137 | ucontext_t uc; |
145 | ucontext_t uc; |
138 | }; |
146 | }; |
139 | |
147 | |
140 | #define coro_transfer(p,n) swapcontext(&((p)->uc), &((n)->uc)) |
148 | #define coro_transfer(p,n) swapcontext(&((p)->uc), &((n)->uc)) |
141 | |
149 | |
142 | #elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX |
150 | #elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX |
143 | |
151 | |
144 | #include <setjmp.h> |
152 | #include <setjmp.h> |
145 | |
153 | |
146 | struct coro_context { |
154 | struct coro_context { |
147 | jmp_buf env; |
155 | jmp_buf env; |