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

@ -7,7 +7,7 @@
#define DC_TOMBSTONE ((struct dc_entry *)1)
struct dc_entry dcache[DCACHE_SIZE];
static spinlock_t dcache_locks[DCACHE_NLOCKS];
static lock_t dcache_locks[DCACHE_NLOCKS];
static u64 dcache_hash(struct dc_entry *parent, const char *name)
{
@ -17,7 +17,7 @@ static u64 dcache_hash(struct dc_entry *parent, const char *name)
return h;
}
static spinlock_t *dcache_lock_for(struct dc_entry *parent, const char *name)
static lock_t *dcache_lock_for(struct dc_entry *parent, const char *name)
{
u64 h = dcache_hash(parent, name);
return &dcache_locks[h & (DCACHE_NLOCKS - 1)];
@ -33,10 +33,10 @@ void dcache_init(void)
void dcache_insert(struct dc_entry *parent, dirent_t *dirent, const char *name)
{
spinlock_t *lock = dcache_lock_for(parent, name);
lock_t *lock = dcache_lock_for(parent, name);
u64 h = dcache_hash(parent, name);
spinlock_acquire(lock);
spin_lock(lock);
for (int i = 0; i < DCACHE_SIZE; i++) {
u32 b = (h + i) & (DCACHE_SIZE - 1);
struct dc_entry *s = &dcache[b];
@ -47,27 +47,27 @@ void dcache_insert(struct dc_entry *parent, dirent_t *dirent, const char *name)
s->parent = parent;
s->dirent = dirent;
memcpy(s->d_name, name, FILE_NAME_MAX_LEN + 1);
spinlock_release(lock);
spin_unlock(lock);
return;
}
}
spinlock_release(lock);
spin_unlock(lock);
}
void dcache_remove(struct dc_entry *d)
{
spinlock_t *lock = dcache_lock_for(d->parent, d->d_name);
lock_t *lock = dcache_lock_for(d->parent, d->d_name);
spinlock_acquire(lock);
spin_lock(lock);
dirent_free(d->dirent);
d->dirent = NULL;
d->parent = DC_TOMBSTONE;
spinlock_release(lock);
spin_unlock(lock);
}
struct dc_entry *dcache_lookup(struct dc_entry *parent, const char *name)
{
CLEANUP_SLOCK spinlock_t *lock = dcache_lock_for(parent, name);
CLEANUP_SLOCK lock_t *lock = dcache_lock_for(parent, name);
u64 h = dcache_hash(parent, name);
struct dc_entry *result = NULL;