summaryrefslogtreecommitdiffstats
path: root/sys/lock.c
blob: 095a08e16e7e0cd1cd6e91a0d84fa45e30f5efe3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "lock.h"

extern int _kernel_panic_unlock;

void
take_mutex(atomic_flag *lock)
{
    if(_kernel_panic_unlock) return;
    while(atomic_flag_test_and_set(lock)) {
        __builtin_ia32_pause();
    }
}

int
try_take_mutex(atomic_flag *lock)
{
    if(_kernel_panic_unlock) return 0;
    return atomic_flag_test_and_set(lock);
}

void
release_mutex(atomic_flag *lock)
{
    atomic_flag_clear(lock);
}