summaryrefslogtreecommitdiff
path: root/kc/core/cpu/irq.c
blob: e4dd29f3cb20573a310c2928072a8f7f1cb6cef3 (plain)
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 "irq.h"

#include <stdatomic.h>

static volatile atomic_uint_fast64_t irq_lock_count = 0;

void irq_lock(void)
{
    irq_lock_count++;
    __asm__ volatile ("cli;");
}

void irq_unlock(void)
{
    if (atomic_load(&irq_lock_count) >= 1)
    {
        irq_lock_count--;
    }

    if (atomic_load(&irq_lock_count) == 0)
    {
        __asm__ volatile ("sti;");
    }
}