From f4940132d84307eb2273dc617fc3defd33764bb7 Mon Sep 17 00:00:00 2001 From: turret Date: Fri, 12 Jan 2024 19:40:47 +0000 Subject: log: implement lock breaking --- init/log.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'init') 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; } -- cgit v1.2.3