aboutsummaryrefslogtreecommitdiffstats
path: root/init/log.c
diff options
context:
space:
mode:
authorturret <turret@duck.com>2024-01-12 19:40:47 +0000
committerturret <turret@duck.com>2024-01-12 19:40:47 +0000
commitf4940132d84307eb2273dc617fc3defd33764bb7 (patch)
tree24769d7aa1fca6b61ce0b3d2fecfaea60f6af48d /init/log.c
parent3ed1e74e16da720dba46d117b12e21b9405ac569 (diff)
downloaddiscord-bot-skeleton-f4940132d84307eb2273dc617fc3defd33764bb7.tar.gz
discord-bot-skeleton-f4940132d84307eb2273dc617fc3defd33764bb7.tar.bz2
discord-bot-skeleton-f4940132d84307eb2273dc617fc3defd33764bb7.zip
log: implement lock breaking
Diffstat (limited to 'init/log.c')
-rw-r--r--init/log.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/init/log.c b/init/log.c
index 5c1b883..9564053 100644
--- a/init/log.c
+++ b/init/log.c
@@ -34,19 +34,25 @@ static const char *mode_to_string[] = {
static int console_lock = 0;
-static void obtain_console_lock()
+#define MAX_TRY_COUNT 2 << 16
+static void obtain_console_lock(void)
{
+ int try_count = 0;
register int rax asm("rax");
retry:
- while(console_lock)
- ;
+ while(console_lock && try_count <= MAX_TRY_COUNT)
+ try_count += 1;
- asm("mov %0, 1\n\t"
+ asm("mov %0, 1 \n"
"xchg %0, %1" : "=r" (rax), "=m" (console_lock));
- if(rax)
+ if(rax > 0 && try_count <= MAX_TRY_COUNT)
goto retry;
+ if(try_count > MAX_TRY_COUNT) {
+ print(LOG_SOH "\3" "4" "log: broken console lock");
+ }
+
return;
}