mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-14 23:28:43 +00:00
2312622923
The coroutine itself may hold some resources when going across pthread cancellable points. Now it is ensured (by semaphores) that either the main process or the coroutine is running so the coroutine is always cancelled inside coro_suspend() where everything is clean but it will change in future. Instead, we explicitly mark the coroutine freeze/cancel points by yielding there -- calling coro_suspend() and checking whether the master process has requested to stop. Where pthread_cancel() was, we instead set a flag and resume that thread to finish its work and exit itself.
25 lines
587 B
C
25 lines
587 B
C
/*
|
|
* BIRD Coroutines
|
|
*
|
|
* (c) 2017 Martin Mares <mj@ucw.cz>
|
|
*
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
*/
|
|
|
|
#ifndef _BIRD_COROUTINE_H_
|
|
#define _BIRD_COROUTINE_H_
|
|
|
|
// The structure is completely opaque, implemented by sysdep
|
|
typedef struct coroutine coroutine;
|
|
|
|
coroutine *coro_new(struct pool *pool, void (*entry_point)(void *arg), void *arg);
|
|
void coro_suspend(void);
|
|
void coro_resume(coroutine *c);
|
|
void coro_done(void *retval) NORET;
|
|
|
|
struct birdsock;
|
|
int coro_sk_read(struct birdsock *s);
|
|
void coro_sk_write(struct birdsock *s, unsigned len);
|
|
|
|
#endif
|