Line data Source code
1 : // Copyright 2024 Accenture. 2 : 3 : /** 4 : * \ingroup async 5 : */ 6 : #ifndef GUARD_C018654B_ADA3_4244_B77C_1B663003B727 7 : #define GUARD_C018654B_ADA3_4244_B77C_1B663003B727 8 : 9 : #include "interrupts/suspendResumeAllInterrupts.h" 10 : 11 : namespace async 12 : { 13 : /** 14 : * A synchronization mechanism that blocks threads from accessing a resource. 15 : * 16 : * The Lock class ensures mutual exclusion, allowing only one thread to access a 17 : * protected resource or function at a time. When a thread acquires the lock, 18 : * any other thread attempting to acquire it is blocked until the lock is released. 19 : * The lock is automatically released in the destructor (RAII idiom). 20 : */ 21 : class Lock 22 : { 23 : public: 24 : Lock(); 25 : ~Lock(); 26 : 27 : private: 28 : OldIntEnabledStatusValueType _oldIntEnabledStatusValue; 29 : }; 30 : 31 : /** 32 : * Inline implementations. 33 : */ 34 483 : inline Lock::Lock() 35 483 : : _oldIntEnabledStatusValue(getOldIntEnabledStatusValueAndSuspendAllInterrupts()) 36 : {} 37 : 38 483 : inline Lock::~Lock() { resumeAllInterrupts(_oldIntEnabledStatusValue); } 39 : 40 : } // namespace async 41 : 42 : #endif // GUARD_C018654B_ADA3_4244_B77C_1B663003B727