summaryrefslogtreecommitdiff
path: root/Kernel/Arch/InterruptDisabler.h
blob: d4e49bb9b4b7727ffcbc3e92dce00ca1792bface (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
26
27
28
29
30
31
32
/*
 * Copyright (c) 2022, Timon Kruiper <timonkruiper@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Types.h>
#include <Kernel/Arch/Processor.h>

namespace Kernel {

class InterruptDisabler {
public:
    InterruptDisabler()
        : m_interrupts_were_enabled(Processor::are_interrupts_enabled())
    {
        Processor::disable_interrupts();
    }

    ~InterruptDisabler()
    {
        if (m_interrupts_were_enabled)
            Processor::enable_interrupts();
    }

private:
    bool m_interrupts_were_enabled;
};

}