Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2024 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #pragma once
12 :
13 : #include "interrupts/suspendResumeAllInterrupts.h"
14 :
15 : namespace interrupts
16 : {
17 : class SuspendResumeAllInterruptsScopedLock
18 : {
19 : public:
20 : // [PUBLICAPI_START]
21 : /**
22 : * Create a lock object instance with disabling of all interrupts
23 : * Store the current interrupt state on instance creation in a private member variable
24 : */
25 8366 : SuspendResumeAllInterruptsScopedLock()
26 8366 : : fOldMachineStateRegisterValue(getMachineStateRegisterValueAndSuspendAllInterrupts())
27 8366 : {}
28 :
29 : /**
30 : * Destroy the lock object instance and restore the internally stored interrupt state from
31 : * before this object instance has been created
32 : */
33 8366 : ~SuspendResumeAllInterruptsScopedLock() { resumeAllInterrupts(fOldMachineStateRegisterValue); }
34 :
35 : // [PUBLICAPI_END]
36 :
37 : private:
38 : uint32_t fOldMachineStateRegisterValue;
39 : };
40 :
41 : } /* namespace interrupts */
|