diff options
author | turret <turret@duck.com> | 2024-01-12 19:40:47 +0000 |
---|---|---|
committer | turret <turret@duck.com> | 2024-01-12 19:40:47 +0000 |
commit | f4940132d84307eb2273dc617fc3defd33764bb7 (patch) | |
tree | 24769d7aa1fca6b61ce0b3d2fecfaea60f6af48d /init/log.c | |
parent | 3ed1e74e16da720dba46d117b12e21b9405ac569 (diff) | |
download | discord-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.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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; } |