1
0
mirror of https://github.com/jrcutler/threadless.io.git synced 2024-07-07 10:35:49 +00:00

Adding coroutine_defer() (with test)

This commit is contained in:
2016-04-10 21:45:20 -04:00
parent aca3db2b06
commit 9acc8a43b4
3 changed files with 79 additions and 0 deletions

View File

@@ -29,6 +29,11 @@ typedef struct coroutine coroutine_t;
*/
typedef void *(coroutine_function_t)(coroutine_t *coro, void *data);
/** Coroutine deferred function type
* @param[in,out] data user-defined data
*/
typedef void (coroutine_deferred_function_t)(void *data);
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -77,6 +82,18 @@ void *coroutine_resume(coroutine_t *coro, void *value);
*/
void *coroutine_yield(coroutine_t *coro, void *value);
/** Defer a function call until coroutine termination
* @param[in,out] coro coroutine
* @param function function to call when @p coro terminates
* @param data user-defined point to pass to @p function
* @retval 0 success
* @retval -1 error
* @post @p function will be called with @p data when @p coro terminates
* @note Registered functions will be called in reverse order of registration
*/
int coroutine_defer(coroutine_t *coro, coroutine_deferred_function_t *function,
void *data);
#ifdef __cplusplus
}
#endif /* __cplusplus */