ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libcoro/coro.h
(Generate patch)

Comparing libcoro/coro.h (file contents):
Revision 1.11 by root, Sat Aug 20 01:03:31 2005 UTC vs.
Revision 1.18 by root, Sun Nov 26 03:19:06 2006 UTC

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,
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 */ 36 */
37 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.
42 */
43
38#ifndef CORO_H 44#ifndef CORO_H
39#define CORO_H 45#define CORO_H
40 46
41#define CORO_VERSION 2 47#define CORO_VERSION 2
42 48
43/* 49/*
44 * Changes since API version 1: 50 * Changes since API version 1:
45 * replaced bogus -DCORO_LOOSE with gramattically more correct -DCORO_LOSER 51 * replaced bogus -DCORO_LOOSE with gramatically more correct -DCORO_LOSER
46 */ 52 */
47 53
48/* 54/*
49 * This library consists of only three files 55 * This library consists of only three files
50 * coro.h, coro.c and LICENSE (and optionally README) 56 * coro.h, coro.c and LICENSE (and optionally README)
55 * 61 *
56 * -DCORO_UCONTEXT 62 * -DCORO_UCONTEXT
57 * 63 *
58 * This flavour uses SUSv2's get/set/swap/makecontext functions that 64 * This flavour uses SUSv2's get/set/swap/makecontext functions that
59 * unfortunately only newer unices support. 65 * unfortunately only newer unices support.
60 * Use this for GNU/Linux + glibc-2.2.3. 66 * Use this for GNU/Linux + glibc-2.2.3 and possibly higher.
61 * 67 *
62 * -DCORO_SJLJ 68 * -DCORO_SJLJ
63 * 69 *
64 * This flavour uses SUSv'2 setjmp/longjmp and sigaltstack functions to 70 * This flavour uses SUSv2's setjmp/longjmp and sigaltstack functions to
65 * do it's job. Coroutine creation is much slower than UCONTEXT, but 71 * do it's job. Coroutine creation is much slower than UCONTEXT, but
66 * context switching is often a bit cheaper. It should work on almost 72 * context switching is often a bit cheaper. It should work on almost
67 * all unices. Use this for GNU/Linux + glibc-2.2. glibc-2.1 and below 73 * all unices. Use this for GNU/Linux + glibc-2.2. glibc-2.1 and below
68 * do not work with any sane model (neither sigaltstack nor context 74 * do not work with any sane model (neither sigaltstack nor context
69 * functions are implemented) 75 * functions are implemented)
70 * 76 *
71 * -DCORO_LINUX 77 * -DCORO_LINUX
72 * 78 *
73 * Old GNU/Linux systems (<= glibc-2.1) work with this implementation 79 * Old GNU/Linux systems (<= glibc-2.1) work with this implementation
74 * (very fast). 80 * (it is very fast and therefore recommended over other methods).
75 * 81 *
76 * -DCORO_LOSER 82 * -DCORO_LOSER
77 * 83 *
78 * Microsoft's highly proprietary platform doesn't support sigaltstack, and 84 * Microsoft's highly proprietary platform doesn't support sigaltstack, and
79 * this automatically selects a suitable workaround for this platform. 85 * this automatically selects a suitable workaround for this platform.
95typedef void (*coro_func)(void *); 101typedef 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 */
102typedef struct coro_context coro_context; 108typedef 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
106 * uninitialized coro_context, it expects a pointer to the entry function 112 * uninitialised coro_context, it expects a pointer to the entry function
107 * and the single pointer value that is given to it as argument. 113 * and the single pointer value that is given to it as argument.
108 * 114 *
109 * Allocating/deallocating the stack is your own responsibility, so there is 115 * Allocating/deallocating the stack is your own responsibility, so there is
110 * no coro_destroy function. 116 * no coro_destroy function.
111 */ 117 */
163 169
164struct coro_context { 170struct coro_context {
165 jmp_buf env; 171 jmp_buf env;
166}; 172};
167 173
174#if CORO_LINUX
168#define coro_transfer(p,n) do { if (!setjmp ((p)->env)) longjmp ((n)->env, 1); } while(0) 175# define coro_transfer(p,n) do { if (!_setjmp ((p)->env)) _longjmp ((n)->env, 1); } while(0)
176#else
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines