From: Matthias Kruk Date: Thu, 21 Nov 2019 07:22:16 +0000 (+0900) Subject: Add spinlock implementation to klibc X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=aa0e4586dd3efe434b34ae7956a4c27220cb798d;p=corax Add spinlock implementation to klibc --- diff --git a/kernel/include/spinlock.h b/kernel/include/spinlock.h new file mode 100644 index 0000000..4ee76f4 --- /dev/null +++ b/kernel/include/spinlock.h @@ -0,0 +1,59 @@ +#ifndef __SPINLOCK_H +#define __SPINLOCK_H + +#include + +/* NOTE: The amd64 implementation in spinlock.S needs this to be an u32_t */ +typedef u32_t spinlock_t; + +/* + * spinlock_lock() - Lock a spinlock, waiting indefinitely + * + * SYNOPSIS + * void spinlock_lock(spinlock_t *lock); + * + * DESCRIPTION + * The spinlock_lock() function will indefinitely attempt to lock + * the spinlock pointed to by `lock' until it succeeds, waiting in + * a busy loop. + * + * RETURN VALUE + * None + */ +void spinlock_lock(spinlock_t*); + +/* + * spinlock_trylock() - Attempt to lock a spinlock + * + * SYNOPSIS + * int spinlock_trylock(spinlock_t *lock); + * + * DESCRIPTION + * The spinlock_trylock() function will attempt once to lock the + * spinlock pointed to by `lock'. This function will not block. + * + * RETURN VALUE + * 0 the caller now holds the lock + * * the spinlock could not be locked + */ +int spinlock_trylock(spinlock_t*); + +/* + * spinlock_unlock() - Unlock a spinlock + * + * SYNOPSIS + * int spinlock_unlock(spinlock_t *lock); + * + * DESCRIPTION + * The spinlock_unlock() function will unlock the spinlock pointed + * to by `lock'. This function will unlock any spinlock regardless + * of spinlock ownership, and the spinlock will always be unlocked + * when this function returns. + * + * RETURN VALUE + * 0 the spinlock was not locked + * * the spinlock was locked + */ +int spinlock_unlock(spinlock_t*); + +#endif /* __SPINLOCK_H */