1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/mm/slab.h"
6
7#include <mos/lib/structures/list.h>
8#include <mos/lib/sync/spinlock.h>
9#include <mos/mos_global.h>
10
11/**
12 * @brief The entry in the waiters list of a process, or a thread
13 */
14typedef struct
15{
16 as_linked_list;
17 tid_t waiter;
18} waitable_list_entry_t;
19
20typedef struct
21{
22 bool closed; // if true, then the process is closed and should not be waited on
23 spinlock_t lock; // protects the waiters list
24 list_head list; // list of threads waiting
25} waitlist_t;
26
27extern slab_t *waitlist_slab;
28
29__BEGIN_DECLS
30
31void waitlist_init(waitlist_t *list);
32__nodiscard bool waitlist_append(waitlist_t *list);
33size_t waitlist_wake(waitlist_t *list, size_t max_wakeups);
34void waitlist_close(waitlist_t *list);
35void waitlist_remove_me(waitlist_t *waitlist);
36
37__END_DECLS
38
39#define waitlist_wake_one(list) waitlist_wake(list, 1)
40#define waitlist_wake_all(list) waitlist_wake(list, SIZE_MAX)
41