mirror of
https://github.com/tailix/libkernaux.git
synced 2024-11-13 11:04:27 -05:00
Add mutex (#69)
This commit is contained in:
parent
87296c0d12
commit
1d838e30db
7 changed files with 56 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
2022-06-18 Alex Kotov <kotovalexarian@gmail.com>
|
||||
|
||||
* include/kernaux/mutex.h: Added
|
||||
|
||||
2022-06-17 Alex Kotov <kotovalexarian@gmail.com>
|
||||
|
||||
* configure.ac: Added package "alloc"
|
||||
|
|
|
@ -21,7 +21,7 @@ libc/libc.la:
|
|||
|
||||
lib_LTLIBRARIES = libkernaux.la
|
||||
|
||||
libkernaux_la_SOURCES = src/libc.h src/assert.c
|
||||
libkernaux_la_SOURCES = src/libc.h src/assert.c src/mutex.c
|
||||
libkernaux_la_LIBADD =
|
||||
|
||||
if ASM_I386
|
||||
|
|
|
@ -44,6 +44,7 @@ zero). Work-in-progress APIs can change at any time.
|
|||
* [Example: Assert](/examples/assert.c)
|
||||
* [Example: Panic](/examples/panic.c)
|
||||
* Stack trace *(planned)*
|
||||
* [Mutex](/include/kernaux/mutex.h) (*non-breaking since* **?.?.?**)
|
||||
* [Input/output](/include/kernaux/io.h) (*work in progress*)
|
||||
* Architecture-specific code (*work in progress*)
|
||||
* [Declarations](/include/kernaux/arch/)
|
||||
|
|
|
@ -4,6 +4,7 @@ nobase_include_HEADERS = \
|
|||
kernaux/arch/riscv64.h \
|
||||
kernaux/arch/x86_64.h \
|
||||
kernaux/assert.h \
|
||||
kernaux/mutex.h \
|
||||
kernaux/version.h
|
||||
|
||||
if ASM_I386
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
#include <kernaux/assert.h>
|
||||
#include <kernaux/mutex.h>
|
||||
#include <kernaux/version.h>
|
||||
|
||||
@comment_line_alloc@#include <kernaux/alloc.h>
|
||||
|
|
26
include/kernaux/mutex.h
Normal file
26
include/kernaux/mutex.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef KERNAUX_INCLUDED_MUTEX
|
||||
#define KERNAUX_INCLUDED_MUTEX
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define KERNAUX_MUTEX_EXTRA_DATA_SIZE (32)
|
||||
|
||||
typedef void (*KernAux_Mutex_Lock )(void *extra_data);
|
||||
typedef void (*KernAux_Mutex_Unlock)(void *extra_data);
|
||||
|
||||
typedef struct KernAux_Mutex {
|
||||
KernAux_Mutex_Lock lock;
|
||||
KernAux_Mutex_Unlock unlock;
|
||||
char extra_data[KERNAUX_MUTEX_EXTRA_DATA_SIZE];
|
||||
} *KernAux_Mutex;
|
||||
|
||||
void KernAux_Mutex_lock (KernAux_Mutex mutex);
|
||||
void KernAux_Mutex_unlock(KernAux_Mutex mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
22
src/mutex.c
Normal file
22
src/mutex.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/assert.h>
|
||||
#include <kernaux/mutex.h>
|
||||
|
||||
void KernAux_Mutex_lock(const KernAux_Mutex mutex)
|
||||
{
|
||||
KERNAUX_ASSERT(mutex);
|
||||
KERNAUX_ASSERT(mutex->lock);
|
||||
|
||||
mutex->lock(mutex->extra_data);
|
||||
}
|
||||
|
||||
void KernAux_Mutex_unlock(const KernAux_Mutex mutex)
|
||||
{
|
||||
KERNAUX_ASSERT(mutex);
|
||||
KERNAUX_ASSERT(mutex->unlock);
|
||||
|
||||
mutex->unlock(mutex->extra_data);
|
||||
}
|
Loading…
Reference in a new issue