pushlock: rewrite implementation

This commit is contained in:
Matheus
2026-07-17 15:58:59 -03:00
parent 06c912dc07
commit fd443a211d
3 changed files with 192 additions and 152 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ typedef pushlock_t mutex_t;
pushlock_acquire_exclusive(m)
#define MUTEX_RELEASE(m) \
pushlock_release(m)
pushlock_release_exclusive(m)
#define MUTEX_TRY(m) \
pushlock_try_acquire_exclusive(m)
+9 -22
View File
@@ -1,31 +1,18 @@
#ifndef _RWLOCK_H
#define _RWLOCK_H
#ifndef _PUSHLOCK_H
#define _PUSHLOCK_H
#include <semaphore.h>
typedef struct pushlock_wait_block_t {
struct pushlock_wait_block_t *next;
size_t shared_count;
semaphore_t semaphore;
} __attribute__((aligned(8))) pushlock_wait_block_t;
#include <stdint.h>
#include <stdbool.h>
typedef uintptr_t pushlock_t;
#define PUSHLOCK_FLAGS_ACQUIRED 1
#define PUSHLOCK_FLAGS_EXCLUSIVE 2
#define PUSHLOCK_FLAGS_CONTENDED 4
#define PUSHLOCK_MASK_FLAGS 0x7
#define PUSHLOCK_MASK_POINTER_SHARED_COUNT (0xfffffffffffffff8lu)
#define PUSHLOCK_GET_POINTER(x) ((pushlock_wait_block_t *)((x) & PUSHLOCK_MASK_POINTER_SHARED_COUNT))
#define PUSHLOCK_GET_SHARED_COUNT(x) ((uintptr_t)PUSHLOCK_GET_POINTER(x) >> 3)
#define PUSHLOCK_INCREMENT_SHARED_COUNT(x) ((x) + 0x8)
#define PUSHLOCK_DECREMENT_SHARED_COUNT(x) ((x) - 0x8)
bool pushlock_try_acquire_exclusive(pushlock_t *pushlock);
void pushlock_acquire_exclusive(pushlock_t *pushlock);
bool pushlock_try_acquire_shared(pushlock_t *pushlock);
void pushlock_acquire_exclusive(pushlock_t *pushlock);
void pushlock_acquire_shared(pushlock_t *pushlock);
void pushlock_release(pushlock_t *pushlock);
void pushlock_release_exclusive(pushlock_t *pushlock);
void pushlock_release_shared(pushlock_t *pushlock);
#endif