1 | /* |
1 | /* |
2 | * Copyright (c) 2001-2005 Marc Alexander Lehmann <schmorp@schmorp.de> |
2 | * Copyright (c) 2001-2006 Marc Alexander Lehmann <schmorp@schmorp.de> |
3 | * |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
4 | * Redistribution and use in source and binary forms, with or without modifica- |
5 | * tion, are permitted provided that the following conditions are met: |
5 | * tion, are permitted provided that the following conditions are met: |
6 | * |
6 | * |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
7 | * 1. Redistributions of source code must retain the above copyright notice, |
… | |
… | |
31 | * |
31 | * |
32 | * This coroutine library is very much stripped down. You should either |
32 | * This coroutine library is very much stripped down. You should either |
33 | * build your own process abstraction using it or - better - just use GNU |
33 | * build your own process abstraction using it or - better - just use GNU |
34 | * Portable Threads, http://www.gnu.org/software/pth/. |
34 | * Portable Threads, http://www.gnu.org/software/pth/. |
35 | * |
35 | * |
|
|
36 | */ |
|
|
37 | |
|
|
38 | /* |
|
|
39 | * 2006-10-26 Include stddef.h on OS X to work around one of its bugs. |
|
|
40 | * Reported by Michael_G_Schwern. |
|
|
41 | * 2006-11-26 Use _setjmp instead of setjmp on GNU/Linux. |
36 | */ |
42 | */ |
37 | |
43 | |
38 | #ifndef CORO_H |
44 | #ifndef CORO_H |
39 | #define CORO_H |
45 | #define CORO_H |
40 | |
46 | |
… | |
… | |
95 | typedef void (*coro_func)(void *); |
101 | typedef void (*coro_func)(void *); |
96 | |
102 | |
97 | /* |
103 | /* |
98 | * A coroutine state is saved in the following structure. Treat it as a |
104 | * A coroutine state is saved in the following structure. Treat it as a |
99 | * opaque type. errno and sigmask might be saved, but don't rely on it, |
105 | * opaque type. errno and sigmask might be saved, but don't rely on it, |
100 | * implement your own switching primitive. |
106 | * implement your own switching primitive if you need it. |
101 | */ |
107 | */ |
102 | typedef struct coro_context coro_context; |
108 | typedef struct coro_context coro_context; |
103 | |
109 | |
104 | /* |
110 | /* |
105 | * This function creates a new coroutine. Apart from a pointer to an |
111 | * This function creates a new coroutine. Apart from a pointer to an |
… | |
… | |
163 | |
169 | |
164 | struct coro_context { |
170 | struct coro_context { |
165 | jmp_buf env; |
171 | jmp_buf env; |
166 | }; |
172 | }; |
167 | |
173 | |
|
|
174 | #if CORO_LINUX |
|
|
175 | # define coro_transfer(p,n) do { if (!_setjmp ((p)->env)) _longjmp ((n)->env, 1); } while(0) |
|
|
176 | #else |
168 | #define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while(0) |
177 | # define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while(0) |
|
|
178 | #endif |
169 | |
179 | |
170 | #endif |
180 | #endif |
171 | |
181 | |
172 | #endif |
182 | #endif |
173 | |
183 | |