diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-28 20:50:36 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-09-28 20:54:43 -0600 |
commit | f410026b7bc96dbb42fec3839dc5d2e41b12f4a4 (patch) | |
tree | 22e831eb47101ee4e3635fcaf2729a81a178823c /libcr_ipc/include | |
parent | f898850c2b4fef03f0d175ec052b3725bd406496 (diff) |
misc
Diffstat (limited to 'libcr_ipc/include')
-rw-r--r-- | libcr_ipc/include/libcr_ipc/mutex.h | 46 | ||||
-rw-r--r-- | libcr_ipc/include/libcr_ipc/sema.h | 6 |
2 files changed, 51 insertions, 1 deletions
diff --git a/libcr_ipc/include/libcr_ipc/mutex.h b/libcr_ipc/include/libcr_ipc/mutex.h new file mode 100644 index 0000000..38ebde0 --- /dev/null +++ b/libcr_ipc/include/libcr_ipc/mutex.h @@ -0,0 +1,46 @@ +/* libcr_ipc/mutex.h - Simple mutexes for libcr (header file) + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-Licence-Identifier: AGPL-3.0-or-later + */ + +#ifndef _COROUTINE_MUTEX_H_ +#define _COROUTINE_MUTEX_H_ + +#include <stdbool.h> /* for bool */ + +#include <libcr/coroutine.h> /* for cid_t */ + +struct _cr_mutex_cid_list { + cid_t val; + struct _cr_mutex_cid_list *next; +}; + +/** + * A cr_mutex_t is a fair mutex. + */ +typedef struct { + bool locked; + struct _cr_mutex_cid_list *head, **tail; +} cr_mutex_t; + +/** + * Lock the mutex. Blocks if it is already locked. + * + * @blocks maybe + * @yields maybe + * @run_in coroutine + */ +void cr_mutex_lock(cr_mutex_t *); + +/** + * Unlock the mutex. Unblocks a coroutine that is blocked on + * cr_mutex_lock(). + * + * @blocks never + * @yields never + * @may_run_in coroutine + */ +void cr_mutex_unluck(cr_mutex_t *); + +#endif /* _COROUTINE_MUTEX_H_ */ diff --git a/libcr_ipc/include/libcr_ipc/sema.h b/libcr_ipc/include/libcr_ipc/sema.h index a2a176d..454eb5d 100644 --- a/libcr_ipc/include/libcr_ipc/sema.h +++ b/libcr_ipc/include/libcr_ipc/sema.h @@ -1,4 +1,4 @@ -/* coroutine_sema.h - Simple semaphores for coroutine.{h,c} +/* libcr_ipc/sema.h - Simple semaphores for libcr (header file) * * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-Licence-Identifier: AGPL-3.0-or-later @@ -7,6 +7,10 @@ #ifndef _COROUTINE_SEMA_H_ #define _COROUTINE_SEMA_H_ +#include <stdbool.h> /* for bool */ + +#include <libcr/coroutine.h> /* for cid_t */ + struct _cr_sema_cid_list { cid_t val; struct _cr_sema_cid_list *next; |