summaryrefslogtreecommitdiffstats
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/makefile2
-rw-r--r--src/kernel/spinlock.C12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/kernel/makefile b/src/kernel/makefile
index c07ae815a..629c39bcb 100644
--- a/src/kernel/makefile
+++ b/src/kernel/makefile
@@ -2,7 +2,7 @@ OBJDIR = ../../obj
include ../../config.mk
OBJS = start.o kernel.o console.o pagemgr.o heapmgr.o taskmgr.o cpumgr.o
-OBJS += syscall.o scheduler.o
+OBJS += syscall.o scheduler.o spinlock.o
OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
all: ${OBJECTS}
diff --git a/src/kernel/spinlock.C b/src/kernel/spinlock.C
new file mode 100644
index 000000000..bfada05c4
--- /dev/null
+++ b/src/kernel/spinlock.C
@@ -0,0 +1,12 @@
+#include <kernel/spinlock.H>
+
+void Spinlock::lock()
+{
+ uint64_t reservation = __sync_fetch_and_add(&iv_reserve, 1);
+ while(iv_ready != reservation);
+}
+
+void Spinlock::unlock()
+{
+ __sync_add_and_fetch(&iv_ready, 1);
+}
OpenPOWER on IntegriCloud