blob: 57d58553f95105f6c6007cef7cabf16d67401aaf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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_ */
|