From 6abd515c051b6dcb545e1033ff129aaaf7293917 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 10 May 2020 13:35:43 +0200 Subject: Added basic spinlock --- src/kernel/io/io.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/kernel/io/io.c b/src/kernel/io/io.c index 2d9d009..dfd9efa 100644 --- a/src/kernel/io/io.c +++ b/src/kernel/io/io.c @@ -66,6 +66,14 @@ void outl(u16 port, u32 data) asm volatile("outl %0, %1" ::"a"(data), "Nd"(port)); } +void spinlock(int *ptr) +{ + int prev; + do + asm volatile("lock xchgl %0,%1" : "=a"(prev) : "m"(*ptr), "a"(1)); + while (prev); +} + void init_serial() { outb(0x3f8 + 1, 0x00); -- cgit v1.2.3