1 /* -*- Mode: c; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ 2 /* 3 libconcurrent 4 Copyright (C) 2010-2016 sharow 5 */ 6 7 #ifndef __CONCURRENT_H__ 8 #define __CONCURRENT_H__ 9 10 #include <stddef.h> 11 #include <stdbool.h> 12 13 14 struct concurrent_ctx; 15 typedef void (*concurrent_proc)(struct concurrent_ctx *); 16 17 typedef enum { 18 CONCURRENT_SUCCESS = 0, 19 CONCURRENT_E_INVALID_ARGUMENT, 20 CONCURRENT_E_STACKSIZE_TOO_SMALL 21 } concurrent_status; 22 23 24 void concurrent_init(void); 25 void concurrent_fin(void); 26 size_t concurrent_sizeof(void); 27 28 concurrent_status 29 concurrent_construct(struct concurrent_ctx *ctx, 30 void *stack_buffer, 31 size_t stack_size, 32 concurrent_proc proc, 33 void *user_ptr); 34 35 void concurrent_destruct(struct concurrent_ctx *ctx); 36 37 void *concurrent_resume_with_value(struct concurrent_ctx *ctx, void *value); 38 void *concurrent_resume(struct concurrent_ctx *ctx); 39 void *concurrent_get_resume_value(struct concurrent_ctx *ctx); 40 void *concurrent_yield_with_value(struct concurrent_ctx *ctx, void *value); 41 void *concurrent_yield(struct concurrent_ctx *ctx); 42 void *concurrent_get_yield_value(struct concurrent_ctx *ctx); 43 void concurrent_reset(struct concurrent_ctx *ctx); 44 void *concurrent_get_user_ptr(struct concurrent_ctx *ctx); 45 size_t concurrent_get_stack_used(struct concurrent_ctx *ctx); 46 void *concurrent_get_stack(struct concurrent_ctx *ctx); 47 bool concurrent_is_done(struct concurrent_ctx *ctx); 48 49 50 #endif 51