PatchworkOS  2ca1c69
A non-POSIX operating system.
Loading...
Searching...
No Matches
mutex.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/sync/mutex.h>
5
6typedef struct aml_thread aml_thread_t;
7
8/**
9 * @brief Mutex
10 * @defgroup modules_acpi_aml_mutex Mutex
11 * @ingroup modules_acpi_aml
12 *
13 * This module provides functionality for acquiring and releasing AML mutexes.
14 *
15 * Note that mutexes currently do... nothing. Instead we just use one big mutex for the entire parser, but we
16 * still implement their behaviour to check for invalid code or errors. This really shouldent matter as AML should only
17 * be getting executed by one thread at a time anyway.
18 *
19 * @see Section 19.6.89 of the ACPI specification for more details.
20 *
21 * @{
22 */
23
24/**
25 * @brief Mutex id.
26 * @typedef aml_mutex_id_t
27 */
29
30/**
31 * @brief Create a new mutex and return its id.
32 *
33 * @param mutex The mutex id to initialize.
34 */
36
37/**
38 * @brief Destroy the mutex with the given id.
39 *
40 * @param mutex The mutex id to destroy.
41 */
43
44/**
45 * @brief Acquire a mutex, blocking until it is available or the timeout is reached.
46 *
47 * If the mutex is already owned by the current thread, this function will return immediately.
48 * If the mutex has a lower SyncLevel than the current SyncLevel, this function will fail.
49 *
50 * @param mutex The mutex to acquire.
51 * @param syncLevel The SyncLevel at which to acquire the mutex.
52 * @param timeout The timeout in clock ticks to wait for the mutex, or `CLOCKS_NEVER` to wait indefinitely.
53 * @return On success, `0`. If timed out, 1. On failure, `ERR` and `errno` is set.
54 */
56
57/**
58 * @brief Release a mutex.
59 *
60 * The mutex must have a SyncLevel equal to the current SyncLevel and must be owned by the current thread.
61 *
62 * @param mutex The mutex to release.
63 * @return On success, `0`. On failure, `ERR` and `errno` is set.
64 */
66
67/** @} */
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
uint8_t aml_sync_level_t
Definition named.h:135
uint64_t aml_mutex_id_t
Mutex id.
Definition mutex.h:28
uint64_t aml_mutex_release(aml_mutex_id_t *mutex)
Release a mutex.
Definition mutex.c:114
void aml_mutex_id_init(aml_mutex_id_t *mutex)
Create a new mutex and return its id.
Definition mutex.c:84
void aml_mutex_id_deinit(aml_mutex_id_t *mutex)
Destroy the mutex with the given id.
Definition mutex.c:89
uint64_t aml_mutex_acquire(aml_mutex_id_t *mutex, aml_sync_level_t syncLevel, clock_t timeout)
Acquire a mutex, blocking until it is available or the timeout is reached.
Definition mutex.c:94
static mtx_t mutex
Definition heap.c:35
struct aml_thread aml_thread_t
Definition mutex.h:6
__UINT64_TYPE__ uint64_t
Definition stdint.h:17