forked from manticoreos/manticore
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
kernel: Add spin lock
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef __MANTICORE_KERNEL_SPINLOCK_H | ||
#define __MANTICORE_KERNEL_SPINLOCK_H | ||
|
||
typedef unsigned long spinlock_t; | ||
|
||
#define SPIN_LOCK_UNLOCKED 0 | ||
#define SPIN_LOCK_LOCKED 1 | ||
|
||
#define DEFINE_SPIN_LOCK(x) spinlock_t x = SPIN_LOCK_UNLOCKED; | ||
|
||
static inline void spin_lock(spinlock_t *lock) | ||
{ | ||
while (!__sync_bool_compare_and_swap(lock, SPIN_LOCK_UNLOCKED, SPIN_LOCK_LOCKED)) | ||
;; | ||
} | ||
|
||
static inline void spin_unlock(spinlock_t *lock) | ||
{ | ||
__sync_bool_compare_and_swap(lock, SPIN_LOCK_LOCKED, SPIN_LOCK_UNLOCKED); | ||
} | ||
|
||
#endif |