lock: merge spinlock and mtx locks into one

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-13 14:19:10 -04:00
commit 2076f1dae1
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
32 changed files with 158 additions and 169 deletions

View file

@ -1,9 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _ht_H_
#define _ht_H_
#ifndef _HASH_H_
#define _HASH_H_
#include <kernel/common.h>
#include <kernel/mtx.h>
#include <kernel/lock.h>
typedef struct ht_entry {
char *key;
@ -19,7 +19,7 @@ typedef struct {
size_t capacity;
size_t size;
mtx_t lock;
lock_t lock;
} ht_t;
ht_t *ht_create(size_t capacity);
@ -30,4 +30,4 @@ int ht_delete(ht_t *ht, const char *key);
void ht_lock(ht_t *ht);
void ht_unlock(ht_t *ht);
#endif /* _ht_H_ */
#endif /* _HASH_H_ */

View file

@ -2,7 +2,7 @@
#ifndef _LIST_H_
#define _LIST_H_
#include <kernel/spinlock.h>
#include <kernel/lock.h>
typedef struct _list_item {
union {
@ -17,7 +17,7 @@ typedef struct _list_item {
typedef struct _list_head {
struct _list_item *head;
struct _list_item *tail;
mtx_t lock;
lock_t lock;
} list_t;
void list_create(list_t *list);

View file

@ -3,7 +3,7 @@
#define _rbtree_tH_
#include <kernel/common.h>
#include <kernel/spinlock.h>
#include <kernel/lock.h>
#define RB_RED 0
#define RB_BLACK 1
@ -26,7 +26,7 @@ typedef struct _rbnode_t {
*/
typedef struct _rbtree_t {
rbnode_t *root;
spinlock_t lock;
lock_t lock;
size_t num_nodes;
} rbtree_t;
@ -40,12 +40,12 @@ rbnode_t *rbt_minimum(rbnode_t *node);
static inline void rbt_lock(rbtree_t *tree)
{
spinlock_acquire(&tree->lock);
spin_lock(&tree->lock);
}
static inline void rbt_unlock(rbtree_t *tree)
{
spinlock_release(&tree->lock);
spin_unlock(&tree->lock);
}
void rbt_init();

View file

@ -2,11 +2,11 @@
#ifndef _RWLOCK_H_
#define _RWLOCK_H_
#include <kernel/spinlock.h>
#include <kernel/lock.h>
#include <kernel/types.h>
typedef struct {
spinlock_t lock;
lock_t lock;
u64 readers;
bool writer;
} rwlock_t;

View file

@ -2,11 +2,11 @@
#ifndef _SEM_H_
#define _SEM_H_
#include <kernel/spinlock.h>
#include <kernel/lock.h>
typedef struct _sem_t {
u64 sem;
spinlock_t lock;
lock_t lock;
} sem_t;
bool sem_trywait(sem_t *sem);