diff --git a/userspace/gui/compositor/compositor.c b/userspace/gui/compositor/compositor.c index 183cf4dd..8de5f6e2 100644 --- a/userspace/gui/compositor/compositor.c +++ b/userspace/gui/compositor/compositor.c @@ -23,6 +23,7 @@ #include "lib/yutani.h" #include "lib/hashmap.h" #include "lib/list.h" +#include "lib/spinlock.h" #include "yutani_int.h" @@ -105,16 +106,6 @@ int32_t max(int32_t a, int32_t b) { return (a > b) ? a : b; } -static void spin_lock(int volatile * lock) { - while(__sync_lock_test_and_set(lock, 0x01)) { - syscall_yield(); - } -} - -static void spin_unlock(int volatile * lock) { - __sync_lock_release(lock); -} - static int next_buf_id(void) { static int _next = 1; return _next++; diff --git a/userspace/gui/terminal/lib/termemu.c b/userspace/gui/terminal/lib/termemu.c index 07069044..726b8e38 100644 --- a/userspace/gui/terminal/lib/termemu.c +++ b/userspace/gui/terminal/lib/termemu.c @@ -9,21 +9,12 @@ #include #include "lib/graphics.h" +#include "lib/spinlock.h" #define MAX_ARGS 1024 static wchar_t box_chars[] = L"▒␉␌␍␊°±␤␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥"; -static void spin_lock(int volatile * lock) { - while(__sync_lock_test_and_set(lock, 0x01)) { - syscall_yield(); - } -} - -static void spin_unlock(int volatile * lock) { - __sync_lock_release(lock); -} - /* Returns the lower of two shorts */ static uint16_t min(uint16_t a, uint16_t b) { return (a < b) ? a : b; diff --git a/userspace/gui/terminal/terminal.c b/userspace/gui/terminal/terminal.c index 9b6cf38e..e30fc662 100644 --- a/userspace/gui/terminal/terminal.c +++ b/userspace/gui/terminal/terminal.c @@ -38,6 +38,7 @@ #include "lib/decorations.h" #include "lib/pthread.h" #include "lib/kbd.h" +#include "lib/spinlock.h" #include "terminal-palette.h" #include "terminal-font.h" @@ -124,16 +125,6 @@ static void set_term_font_size(float s) { reinit(1); } -static void spin_lock(int volatile * lock) { - while(__sync_lock_test_and_set(lock, 0x01)) { - syscall_yield(); - } -} - -static void spin_unlock(int volatile * lock) { - __sync_lock_release(lock); -} - /* Returns the lower of two shorts */ int32_t min(int32_t a, int32_t b) { return (a < b) ? a : b; diff --git a/userspace/tests/test-threads.c b/userspace/tests/test-threads.c index 7740aae7..5c1ef20d 100644 --- a/userspace/tests/test-threads.c +++ b/userspace/tests/test-threads.c @@ -12,6 +12,7 @@ #include #include #include "lib/pthread.h" +#include "lib/spinlock.h" #define NUM_THREADS 5 #define VALUE 0x1000000 @@ -20,17 +21,7 @@ volatile uint32_t result = 0; int8_t use_locks = 0; -volatile uint8_t the_lock = 0; - -void spin_lock(uint8_t volatile * lock) { - while(__sync_lock_test_and_set(lock, 0x01)) { - ;; /* oh god */ - } -} - -void spin_unlock(uint8_t volatile * lock) { - __sync_lock_release(lock); -} +volatile int the_lock = 0; void *print_pid(void * garbage) { int i;