30 lines
450 B
C
30 lines
450 B
C
|
#pragma once
|
||
|
|
||
|
#include <stdint.h>
|
||
|
|
||
|
class Mutex {
|
||
|
public:
|
||
|
Mutex(const char* name) : name_(name) {}
|
||
|
|
||
|
void Lock();
|
||
|
void Unlock() { lock_ = false; }
|
||
|
|
||
|
private:
|
||
|
const char* name_;
|
||
|
|
||
|
uint8_t lock_ = 0;
|
||
|
};
|
||
|
|
||
|
class MutexHolder {
|
||
|
public:
|
||
|
MutexHolder(Mutex& mutex) : mutex_(mutex) { mutex_.Lock(); }
|
||
|
|
||
|
~MutexHolder() { mutex_.Unlock(); }
|
||
|
|
||
|
MutexHolder(MutexHolder&) = delete;
|
||
|
MutexHolder(MutexHolder&&) = delete;
|
||
|
|
||
|
private:
|
||
|
Mutex& mutex_;
|
||
|
};
|