diff --git a/amd64/include/kernel/mtx.h b/amd64/include/kernel/mtx.h deleted file mode 100644 index 43adaa3..0000000 --- a/amd64/include/kernel/mtx.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _MTX_H_ -#define _MTX_H_ - -#include - -void mtx_lock(mtx_t *l); -void mtx_unlock(mtx_t *l); - -#endif /* _MTX_H_ */ diff --git a/amd64/include/kernel/spinlock.h b/amd64/include/kernel/spinlock.h deleted file mode 100644 index a41d463..0000000 --- a/amd64/include/kernel/spinlock.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _SPINLOCK_H_ -#define _SPINLOCK_H_ - -#include -#include - -#define CLEANUP_SLOCK CLEANUP(cleanup_spinlock) - -typedef u32 spinlock_t; -typedef spinlock_t mtx_t; - -void spinlock_acquire(spinlock_t *lock); -void spinlock_release(spinlock_t *lock); -void cleanup_spinlock(spinlock_t **lock_ptr); - -#endif /* _SPINLOCK_H_ */ diff --git a/amd64/kernel/Makefile b/amd64/kernel/Makefile index 8cf7dcb..28ab37c 100644 --- a/amd64/kernel/Makefile +++ b/amd64/kernel/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += atomic.o -obj-y += spinlock.o +obj-y += lock.o obj-y += thread.o obj-y += time.o obj-y += tsc.o diff --git a/amd64/kernel/spinlock.c b/amd64/kernel/lock.c similarity index 55% rename from amd64/kernel/spinlock.c rename to amd64/kernel/lock.c index 9504916..10b3bac 100644 --- a/amd64/kernel/spinlock.c +++ b/amd64/kernel/lock.c @@ -1,39 +1,39 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include -#include +#include #include #include #include -static uint64_t spinlock_attempt_acquire(spinlock_t *lock) +static uint64_t spinlock_attempt_acquire(lock_t *lock) { return atomic_cmpxchg(lock, 0, 1); } -void spinlock_acquire(spinlock_t *lock) +void spin_lock(lock_t *lock) { while (spinlock_attempt_acquire(lock)) ; } -void spinlock_release(spinlock_t *lock) +void spin_unlock(lock_t *lock) { atomic_cmpxchg(lock, 1, 0); } -void cleanup_spinlock(spinlock_t **lock_ptr) +void cleanup_spinlock(lock_t **lock_ptr) { if (lock_ptr && *lock_ptr) - spinlock_release(*lock_ptr); + spin_unlock(*lock_ptr); } -void mtx_lock(mtx_t *l) +void mtx_lock(lock_t *l) { while (spinlock_attempt_acquire(l)) reschedule(THREAD_STATE_WAITING); } -void mtx_unlock(mtx_t *l) +void mtx_unlock(lock_t *l) { - spinlock_release(l); + spin_unlock(l); } diff --git a/fs/fat32/inode.h b/fs/fat32/inode.h index ddb3ca6..fd739ba 100644 --- a/fs/fat32/inode.h +++ b/fs/fat32/inode.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include diff --git a/fs/vfs/dcache.c b/fs/vfs/dcache.c index ad171e7..5bb84b6 100644 --- a/fs/vfs/dcache.c +++ b/fs/vfs/dcache.c @@ -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; diff --git a/fs/vfs/inode.c b/fs/vfs/inode.c index 4069eab..11cd7f9 100644 --- a/fs/vfs/inode.c +++ b/fs/vfs/inode.c @@ -52,19 +52,18 @@ int dirent_populate_children(dirent_t *dir) kfree(dents); return 0; -cleanup: - { - list_item_t *item = inode->dirents.head; - while (item) { - dirent_t *dent = item->ptr; - list_item_t *next = item->next; - list_remove(item); - if (dent->inode) - inode_dec_ref(dent->inode); - dirent_free(dent); - item = next; - } +cleanup: { + list_item_t *item = inode->dirents.head; + while (item) { + dirent_t *dent = item->ptr; + list_item_t *next = item->next; + list_remove(item); + if (dent->inode) + inode_dec_ref(dent->inode); + dirent_free(dent); + item = next; } +} list_unlock(&inode->dirents); write_unlock(&inode->rwlock); kfree(dents); @@ -162,21 +161,21 @@ void inode_dec_ref(inode_t *inode) void dirent_inc_ref(dirent_t *dent) { - spinlock_acquire(&dent->lock); + spin_lock(&dent->lock); dent->refcount += 1; - spinlock_release(&dent->lock); + spin_unlock(&dent->lock); } void dirent_dec_ref(dirent_t *dent) { - spinlock_acquire(&dent->lock); + spin_lock(&dent->lock); if (dent->refcount == 0) { - spinlock_release(&dent->lock); + spin_unlock(&dent->lock); return; } dent->refcount -= 1; bool freed = (dent->refcount == 0); - spinlock_release(&dent->lock); + spin_unlock(&dent->lock); if (freed) { inode_dec_ref(dent->inode); diff --git a/fs/vfs/mount.c b/fs/vfs/mount.c index 418b395..9c9afd7 100644 --- a/fs/vfs/mount.c +++ b/fs/vfs/mount.c @@ -8,7 +8,7 @@ #include static struct mount *root_mount = NULL; -static spinlock_t mount_lock = 0; +static lock_t mount_lock = 0; fs_t *vfs_get_root(void) { @@ -24,19 +24,19 @@ struct mount *vfs_get_root_mount(void) struct mount *mount_find_child(struct mount *parent, dirent_t *dent) { - spinlock_acquire(&mount_lock); + spin_lock(&mount_lock); list_item_t *item = parent->children.head; while (item) { struct mount *m = item->ptr; if (m->mountpoint == dent) { - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return m; } item = item->next; } - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return NULL; } @@ -65,16 +65,16 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags) return -EINVAL; if (!path) { - spinlock_acquire(&mount_lock); + spin_lock(&mount_lock); if (root_mount) { - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -EBUSY; } struct mount *m = kzalloc(sizeof(*m), ALLOC_KERN); if (!m) { - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -ENOMEM; } @@ -86,7 +86,7 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags) list_create(&m->children); root_mount = m; - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return 0; } @@ -101,14 +101,14 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags) return -ENOTDIR; } - spinlock_acquire(&mount_lock); + spin_lock(&mount_lock); list_item_t *item = parent->children.head; while (item) { struct mount *m = item->ptr; if (m->mountpoint == mp) { dirent_dec_ref(mp); - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -EBUSY; } item = item->next; @@ -117,7 +117,7 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags) struct mount *m = kzalloc(sizeof(*m), ALLOC_KERN); if (!m) { dirent_dec_ref(mp); - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -ENOMEM; } @@ -134,11 +134,11 @@ int vfs_mount(const char *path, fs_t *fs, u64 flags) if (!m->child_link) { dirent_dec_ref(mp); kfree(m); - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -ENOMEM; } - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return 0; } @@ -153,7 +153,7 @@ int vfs_umount(const char *path) if (res < 0) return res; - spinlock_acquire(&mount_lock); + spin_lock(&mount_lock); struct mount *target = NULL; list_item_t *item = parent->children.head; @@ -169,17 +169,17 @@ int vfs_umount(const char *path) dirent_dec_ref(mp); if (!target) { - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -EINVAL; } if (target == root_mount) { - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -EINVAL; } if (target->children.head) { - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return -EBUSY; } @@ -189,6 +189,6 @@ int vfs_umount(const char *path) dirent_dec_ref(target->mountpoint); kfree(target); - spinlock_release(&mount_lock); + spin_unlock(&mount_lock); return 0; } diff --git a/fs/vfs/uapi.c b/fs/vfs/uapi.c index 781a561..8287177 100644 --- a/fs/vfs/uapi.c +++ b/fs/vfs/uapi.c @@ -76,7 +76,7 @@ static int sys_open(const char *path, int flags) if (res < 0) return res; - spinlock_acquire(&thread->fd_lock); + spin_lock(&thread->fd_lock); int fdno = -1; @@ -109,7 +109,7 @@ static int sys_open(const char *path, int flags) fdno = osize; } - spinlock_release(&thread->fd_lock); + spin_unlock(&thread->fd_lock); return fdno; } @@ -125,12 +125,12 @@ static int sys_close(int fd) if (!f->dirent) return -EBADF; - spinlock_acquire(&thread->fd_lock); + spin_lock(&thread->fd_lock); vfs_close(f->dirent); memset(f, 0, sizeof(struct file)); - spinlock_acquire(&thread->fd_lock); + spin_lock(&thread->fd_lock); return 0; } diff --git a/fs/vfs/vfs.c b/fs/vfs/vfs.c index 194f6b6..3301dae 100644 --- a/fs/vfs/vfs.c +++ b/fs/vfs/vfs.c @@ -58,20 +58,20 @@ static int next_level(const char *path, dirent_t *dent, dirent_t **out_dirent) if (res < 0) return -ENOENT; - spinlock_acquire(&dirent->lock); + spin_lock(&dirent->lock); if (!dirent->inode) { fs_t *fs = dent->fs; u64 inum = dirent->ino_num; res = fs->fs_ops.open_inode(fs, inum, dirent, &dirent->inode); if (res < 0) { - spinlock_release(&dirent->lock); + spin_unlock(&dirent->lock); dirent_dec_ref(dirent); return res; } } - spinlock_release(&dirent->lock); + spin_unlock(&dirent->lock); *out_dirent = dirent; return i; diff --git a/include/fs/dcache.h b/include/fs/dcache.h index d9e0125..65c0321 100644 --- a/include/fs/dcache.h +++ b/include/fs/dcache.h @@ -2,21 +2,21 @@ #ifndef _DCACHE_H_ #define _DCACHE_H_ -#include +#include #include #include #define DCACHE_SHIFT 10 -#define DCACHE_SIZE (1 << DCACHE_SHIFT) +#define DCACHE_SIZE (1 << DCACHE_SHIFT) #define DCACHE_LOCK_SHIFT 4 -#define DCACHE_NLOCKS (1 << DCACHE_LOCK_SHIFT) +#define DCACHE_NLOCKS (1 << DCACHE_LOCK_SHIFT) struct dc_entry { struct dc_entry *parent; struct mount *mount; - spinlock_t lock; + lock_t lock; list_t children; dirent_t *dirent; char d_name[FILE_NAME_MAX_LEN + 1]; diff --git a/include/fs/inode.h b/include/fs/inode.h index 87a8b18..004b454 100644 --- a/include/fs/inode.h +++ b/include/fs/inode.h @@ -49,7 +49,7 @@ struct _dirent { u64 flags; u64 type; - spinlock_t lock; + lock_t lock; u64 refcount; diff --git a/include/fs/vfs.h b/include/fs/vfs.h index ca93033..8824184 100644 --- a/include/fs/vfs.h +++ b/include/fs/vfs.h @@ -2,7 +2,7 @@ #ifndef _VFS_H_ #define _VFS_H_ -#include +#include #include #include @@ -79,7 +79,7 @@ struct _fs { bool mounted; dirent_t *mount_point; - spinlock_t lock; + lock_t lock; struct fs_ops fs_ops; }; diff --git a/include/kernel/driver.h b/include/kernel/driver.h index 65d4656..46f7f5f 100644 --- a/include/kernel/driver.h +++ b/include/kernel/driver.h @@ -3,7 +3,7 @@ #define _DRIVER_H_ #include -#include +#include #include #include diff --git a/include/kernel/lock.h b/include/kernel/lock.h new file mode 100644 index 0000000..75af3f2 --- /dev/null +++ b/include/kernel/lock.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _LOCK_H_ +#define _LOCK_H_ + +#include +#include + +#define CLEANUP_SLOCK CLEANUP(cleanup_spinlock) + +typedef u32 lock_t; + +void spin_lock(lock_t *lock); +void spin_unlock(lock_t *lock); +void cleanup_spinlock(lock_t **lock_ptr); + +void mtx_lock(lock_t *l); +void mtx_unlock(lock_t *l); + +#endif /* _LOCK_H_ */ diff --git a/include/kernel/mem.h b/include/kernel/mem.h index 7540d56..431373e 100644 --- a/include/kernel/mem.h +++ b/include/kernel/mem.h @@ -3,7 +3,7 @@ #define _MEM_H_ #include -#include +#include #define ALIGN(_a) __attribute__((aligned(_a))) #define PHYSICAL_PAGE_MASK (~(hhdm_start)) diff --git a/include/kernel/slab.h b/include/kernel/slab.h index 7392629..543f871 100644 --- a/include/kernel/slab.h +++ b/include/kernel/slab.h @@ -3,7 +3,7 @@ #define _SLAB_H_ #include -#include +#include #define ALLOC_KERN 0x1 #define ALLOC_USER 0x2 @@ -19,7 +19,7 @@ typedef struct _mem_cache_t { size_t num_members; size_t num_free; vaddr_t next_free; - spinlock_t lock; + lock_t lock; struct _mem_cache_t *next; } mem_cache_t; diff --git a/include/kernel/thread.h b/include/kernel/thread.h index f3ede78..3eee644 100644 --- a/include/kernel/thread.h +++ b/include/kernel/thread.h @@ -3,7 +3,7 @@ #define _THREAD_H_ #include -#include +#include #include #include #include @@ -33,7 +33,7 @@ struct file { u64 flags; u64 offset; u64 refcount; - spinlock_t lock; + lock_t lock; }; struct thread { @@ -53,15 +53,15 @@ struct thread { pgd_t *pgd; - spinlock_t mem_lock; + lock_t mem_lock; rbtree_t memmap; - spinlock_t alloc_lock; + lock_t alloc_lock; rbtree_t alloc_map; uaddr_t entry; - spinlock_t fd_lock; + lock_t fd_lock; size_t fd_array_size; struct file *fdt; diff --git a/include/lib/hashchain.h b/include/lib/hashchain.h index 77c0ad4..5c83238 100644 --- a/include/lib/hashchain.h +++ b/include/lib/hashchain.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _ht_H_ -#define _ht_H_ +#ifndef _HASH_H_ +#define _HASH_H_ #include -#include +#include 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_ */ diff --git a/include/lib/list.h b/include/lib/list.h index d8fbaee..6cedf7c 100644 --- a/include/lib/list.h +++ b/include/lib/list.h @@ -2,7 +2,7 @@ #ifndef _LIST_H_ #define _LIST_H_ -#include +#include 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); diff --git a/include/lib/rbtree.h b/include/lib/rbtree.h index 210375a..de5cdd3 100644 --- a/include/lib/rbtree.h +++ b/include/lib/rbtree.h @@ -3,7 +3,7 @@ #define _rbtree_tH_ #include -#include +#include #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(); diff --git a/include/lib/rwlock.h b/include/lib/rwlock.h index 50a1fc1..7812bef 100644 --- a/include/lib/rwlock.h +++ b/include/lib/rwlock.h @@ -2,11 +2,11 @@ #ifndef _RWLOCK_H_ #define _RWLOCK_H_ -#include +#include #include typedef struct { - spinlock_t lock; + lock_t lock; u64 readers; bool writer; } rwlock_t; diff --git a/include/lib/sem.h b/include/lib/sem.h index 3f12616..eec3c2a 100644 --- a/include/lib/sem.h +++ b/include/lib/sem.h @@ -2,11 +2,11 @@ #ifndef _SEM_H_ #define _SEM_H_ -#include +#include typedef struct _sem_t { u64 sem; - spinlock_t lock; + lock_t lock; } sem_t; bool sem_trywait(sem_t *sem); diff --git a/kernel/thread/sched.c b/kernel/thread/sched.c index 51390f6..4cdde49 100644 --- a/kernel/thread/sched.c +++ b/kernel/thread/sched.c @@ -7,24 +7,24 @@ static struct { struct thread *head; struct thread *tail; - spinlock_t lock; + lock_t lock; } sched_queue; void sched_add_thread(struct thread *t) { - spinlock_acquire(&sched_queue.lock); + spin_lock(&sched_queue.lock); t->next = NULL; if (sched_queue.tail) sched_queue.tail->next = t; sched_queue.tail = t; if (!sched_queue.head) sched_queue.head = t; - spinlock_release(&sched_queue.lock); + spin_unlock(&sched_queue.lock); } void sched_remove_thread(struct thread *del) { - spinlock_acquire(&sched_queue.lock); + spin_lock(&sched_queue.lock); struct thread *t = sched_queue.head; struct thread *p = NULL; while (t) { @@ -43,12 +43,12 @@ void sched_remove_thread(struct thread *del) p = t; t = t->next; } - spinlock_release(&sched_queue.lock); + spin_unlock(&sched_queue.lock); } static struct thread *dequeue_thread() { - spinlock_acquire(&sched_queue.lock); + spin_lock(&sched_queue.lock); struct thread *t = sched_queue.head; if (t) { sched_queue.head = t->next; @@ -58,7 +58,7 @@ static struct thread *dequeue_thread() } else { t = tls_get()->idle_thread; } - spinlock_release(&sched_queue.lock); + spin_unlock(&sched_queue.lock); return t; } diff --git a/kernel/thread/thread.c b/kernel/thread/thread.c index a5ca22a..0c24721 100644 --- a/kernel/thread/thread.c +++ b/kernel/thread/thread.c @@ -19,9 +19,9 @@ tid_t alloc_tid() void thread_mmap(struct thread *thread, paddr_t p, vaddr_t v, size_t len, u64 flags) { - spinlock_acquire(&thread->mem_lock); + spin_lock(&thread->mem_lock); page_map(thread->pgd, p, v, len, flags, &thread->memmap); - spinlock_release(&thread->mem_lock); + spin_unlock(&thread->mem_lock); } void *thread_alloc(struct thread *thread, size_t size) @@ -31,8 +31,8 @@ void *thread_alloc(struct thread *thread, size_t size) static int copy_parent_memmap(struct thread *child, struct thread *parent) { - spinlock_acquire(&parent->mem_lock); - spinlock_acquire(&child->mem_lock); + spin_lock(&parent->mem_lock); + spin_lock(&child->mem_lock); rbnode_t *node = parent->memmap.root; if (!node) @@ -46,8 +46,8 @@ static int copy_parent_memmap(struct thread *child, struct thread *parent) void *pages = kalloc(area->len, ALLOC_USER); if (!pages) { - spinlock_release(&child->mem_lock); - spinlock_release(&parent->mem_lock); + spin_unlock(&child->mem_lock); + spin_unlock(&parent->mem_lock); return -ENOMEM; } @@ -58,8 +58,8 @@ static int copy_parent_memmap(struct thread *child, struct thread *parent) } done: - spinlock_release(&child->mem_lock); - spinlock_release(&parent->mem_lock); + spin_unlock(&child->mem_lock); + spin_unlock(&parent->mem_lock); return 0; } @@ -119,14 +119,14 @@ struct thread *thread_fork(struct thread *parent) return NULL; } - spinlock_acquire(&parent->fd_lock); + spin_lock(&parent->fd_lock); if (parent->fd_array_size) { child->fd_array_size = parent->fd_array_size; child->fdt = kalloc(child->fd_array_size * sizeof(struct file), ALLOC_KERN); if (child->fdt) memcpy(child->fdt, parent->fdt, child->fd_array_size * sizeof(struct file)); } - spinlock_release(&parent->fd_lock); + spin_unlock(&parent->fd_lock); child->group = child->tid; diff --git a/lib/hashchain.c b/lib/hashchain.c index 841bd2c..eee37ff 100644 --- a/lib/hashchain.c +++ b/lib/hashchain.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include #include -#include #include #include #include diff --git a/lib/list.c b/lib/list.c index 2e830cf..097abc8 100644 --- a/lib/list.c +++ b/lib/list.c @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include #include #include #include diff --git a/lib/printf.c b/lib/printf.c index 443d91c..3b5e226 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -40,7 +40,7 @@ #include #include -#include +#include // define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the // printf_config.h header file @@ -941,14 +941,14 @@ static int _vsnprintf(out_fct_type out, char *buffer, const size_t maxlen, const int printf_(const char *format, ...) { - static spinlock_t lock = 0; - spinlock_acquire(&lock); + static lock_t lock = 0; + spin_lock(&lock); va_list va; va_start(va, format); char buffer[1]; const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va); va_end(va); - spinlock_release(&lock); + spin_unlock(&lock); return ret; } diff --git a/lib/rwlock.c b/lib/rwlock.c index 48e1944..d6c1161 100644 --- a/lib/rwlock.c +++ b/lib/rwlock.c @@ -4,41 +4,41 @@ void read_lock(rwlock_t *lock) { while (1) { - spinlock_acquire(&lock->lock); + spin_lock(&lock->lock); if (!lock->writer) { lock->readers++; - spinlock_release(&lock->lock); + spin_unlock(&lock->lock); return; } - spinlock_release(&lock->lock); + spin_unlock(&lock->lock); } } void read_unlock(rwlock_t *lock) { - spinlock_acquire(&lock->lock); + spin_lock(&lock->lock); lock->readers--; - spinlock_release(&lock->lock); + spin_unlock(&lock->lock); } void write_lock(rwlock_t *lock) { while (1) { - spinlock_acquire(&lock->lock); + spin_lock(&lock->lock); if (!lock->writer && lock->readers == 0) { lock->writer = true; - spinlock_release(&lock->lock); + spin_unlock(&lock->lock); return; } - spinlock_release(&lock->lock); + spin_unlock(&lock->lock); } } void write_unlock(rwlock_t *lock) { - spinlock_acquire(&lock->lock); + spin_lock(&lock->lock); lock->writer = false; - spinlock_release(&lock->lock); + spin_unlock(&lock->lock); } void rwlock_init(rwlock_t *lock) diff --git a/lib/sem.c b/lib/sem.c index 575f14f..f777070 100644 --- a/lib/sem.c +++ b/lib/sem.c @@ -5,12 +5,12 @@ bool sem_trywait(sem_t *sem) { bool ret = false; - spinlock_acquire(&sem->lock); + spin_lock(&sem->lock); if (sem->sem > 0) { sem->sem -= 1; ret = true; } - spinlock_release(&sem->lock); + spin_unlock(&sem->lock); return ret; } @@ -23,9 +23,9 @@ void sem_wait(sem_t *sem) void sem_post(sem_t *sem) { - spinlock_acquire(&sem->lock); + spin_lock(&sem->lock); sem->sem += 1; - spinlock_release(&sem->lock); + spin_unlock(&sem->lock); } void sem_init(sem_t *sem, size_t n_res) diff --git a/mem/buddy.c b/mem/buddy.c index 20b3238..6b23a3c 100644 --- a/mem/buddy.c +++ b/mem/buddy.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -36,7 +36,7 @@ struct buddy_zone { vaddr_t usable_base; size_t usable_len; - spinlock_t lock; + lock_t lock; }; static struct buddy_zone buddy_zones[128] = {0}; @@ -112,7 +112,7 @@ static void alloc_split(struct buddy_zone *bzone, void *alloc, size_t cur_order, static void *try_alloc(struct buddy_zone *bzone, size_t order) { void *ret = NULL; - spinlock_acquire(&bzone->lock); + spin_lock(&bzone->lock); for (size_t i = order; i <= bzone->max_order; i++) { if (bzone->order_freelists[i]) { @@ -126,7 +126,7 @@ static void *try_alloc(struct buddy_zone *bzone, size_t order) if (ret) bzone->space_free -= PAGE_SIZE << order; - spinlock_release(&bzone->lock); + spin_unlock(&bzone->lock); return ret; } @@ -276,9 +276,9 @@ void buddy_free(void *ptr) struct buddy_zone *zone = buddy_zones + i; vaddr_t p = (vaddr_t)ptr; if (p >= zone->usable_base && p < zone->usable_base + zone->usable_len) { - spinlock_acquire(&zone->lock); + spin_lock(&zone->lock); buddy_zone_free(zone, ptr); - spinlock_release(&zone->lock); + spin_unlock(&zone->lock); } } } diff --git a/mem/slab.c b/mem/slab.c index d18a60c..c7b23ca 100644 --- a/mem/slab.c +++ b/mem/slab.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -50,7 +50,7 @@ void *slab_alloc(mem_cache_t *cache) return NULL; void *ret = NULL; - spinlock_acquire(&cache->lock); + spin_lock(&cache->lock); if (cache->num_free > 0) { u64 *next = (u64 *)cache->next_free; @@ -67,7 +67,7 @@ void *slab_alloc(mem_cache_t *cache) ret = slab_alloc(cache->next); } - spinlock_release(&cache->lock); + spin_unlock(&cache->lock); return ret; } @@ -83,7 +83,7 @@ void slab_free(mem_cache_t *cache, void *ptr) vaddr_t pcache = (vaddr_t)cache; vaddr_t pcache_start = pcache + cache->offset; - spinlock_acquire(&cache->lock); + spin_lock(&cache->lock); if (pptr >= pcache_start && pptr <= pcache_start + (cache->num_members - 1) * cache->item_size) { if ((pptr - pcache_start) % cache->item_size) { @@ -103,7 +103,7 @@ void slab_free(mem_cache_t *cache, void *ptr) } } - spinlock_release(&cache->lock); + spin_unlock(&cache->lock); } void cleanup_kfree(void **ptr)