CppELib 1.7.0
Loading...
Searching...
No Matches
Mutex.h
Go to the documentation of this file.
1#ifndef OS_WRAPPER_MUTEX_H_INCLUDED
2#define OS_WRAPPER_MUTEX_H_INCLUDED
3
4#include "Timeout.h"
5#include "OSWrapperError.h"
6
7namespace OSWrapper {
8
9class MutexFactory;
10
17void registerMutexFactory(MutexFactory* factory);
18
22class Mutex {
23protected:
24 virtual ~Mutex() {}
25
26public:
33 static Mutex* create();
34
42 static Mutex* create(int priorityCeiling);
43
50 static void destroy(Mutex* m);
51
59 virtual Error lock() = 0;
60
68 virtual Error tryLock() = 0;
69
80 virtual Error timedLock(Timeout tmout) = 0;
81
87 virtual Error unlock() = 0;
88
89};
90
91
99class LockGuard {
100public:
101 struct AdoptLock {};
102 static const AdoptLock ADOPT_LOCK;
103
110 explicit LockGuard(Mutex* m);
111
117 LockGuard(Mutex* m, AdoptLock adoptLock);
118
124 ~LockGuard();
125
126private:
127 Mutex* m_mutex;
128 Error m_lockErr;
129
130 LockGuard(const LockGuard&);
131 LockGuard& operator=(const LockGuard&);
132};
133
134}
135
136#endif // OS_WRAPPER_MUTEX_H_INCLUDED
RAII wrapper of Mutex.
Definition Mutex.h:99
~LockGuard()
Destructor of LockGuard.
Definition Mutex.cpp:50
static const AdoptLock ADOPT_LOCK
Used as argument of LockGuard's constructor.
Definition Mutex.h:102
Abstract class that has functions of common RTOS's mutex.
Definition Mutex.h:22
virtual Error lock()=0
Block the current thread until locks this mutex.
static Mutex * create()
Create a Mutex object.
Definition Mutex.cpp:14
virtual Error timedLock(Timeout tmout)=0
Block the current thread until locks this mutex but only within the limited time.
static void destroy(Mutex *m)
Destroy a Mutex object.
Definition Mutex.cpp:26
virtual Error tryLock()=0
Try to lock this mutex without blocking.
virtual Error unlock()=0
Unlock this mutex that the current thread locks.
virtual ~Mutex()
Definition Mutex.h:24
Value object for the timeout.
Definition Timeout.h:11
OSWrapper provides abstract C++ interface of common RTOS: thread, mutex, event flag,...
Definition EventFlag.cpp:5
void registerMutexFactory(MutexFactory *factory)
Register the MutexFactory.
Definition Mutex.cpp:9
Error
Kinds of errors of the OS objects.
Definition OSWrapperError.h:9
Definition Mutex.h:101