diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-26 19:31:05 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-26 19:31:05 -0600 |
commit | f5da707e77ee954b12f3c961012e4f40fa4e1bd3 (patch) | |
tree | 6a9ddcdd487ee5c60f3c8570866b813e5fe74d9e /coroutine_sema.h | |
parent | a9acf65bc8e3439d7fd2c927b2a920f120cb3a47 (diff) |
races
Diffstat (limited to 'coroutine_sema.h')
-rw-r--r-- | coroutine_sema.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/coroutine_sema.h b/coroutine_sema.h new file mode 100644 index 0000000..57d5855 --- /dev/null +++ b/coroutine_sema.h @@ -0,0 +1,35 @@ +/* coroutine_sema.h - Simple semaphores for coroutine.{h,c} + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-Licence-Identifier: AGPL-3.0-or-later + */ + +#ifndef _COROUTINE_SEMA_H_ +#define _COROUTINE_SEMA_H_ + +/** + * A cr_sema_t is a fair unbounded[1] counting semaphore. + * + * [1]: Well, INT_MAX + */ +typedef struct sema_t cr_sema_t; + +/** + * Increment the semaphore, + * + * @blocks never + * @yields never + * @run_in anywhere (coroutine, sighandler) + */ +void cr_sema_signal(cr_sema_t *sema); + +/** + * Wait until the semaphore is >0, then decrement it. + * + * @blocks maybe + * @yields maybe + * @may_run_in coroutine + */ +void cr_sema_wait(cr_sema_t *sema); + +#endif /* _COROUTINE_SEMA_H_ */ |