Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
Mutex.h
Go to the documentation of this file.
1 #ifndef MUTEX_H
2 #define MUTEX_H
3 
4 #include "Types.h"
5 #include <pthread.h>
6 #include <errno.h>
7 #include <cstdio>
8 
9 class tcCondition;
10 
11 class tcMutex
12 {
13 public:
14  tcMutex(bool recursive = true);
15 
16  ~tcMutex();
17 
18  inline void lock()
19  {
20  int ret = pthread_mutex_lock(&mhMutex);
21  if (ret == EOWNERDEAD) {
22  if (pthread_mutex_consistent(&mhMutex) != 0) {
23  perror("pthread_mutex_consistent failed");
24  }
25  }
26  }
27 
28  inline void unlock()
29  {
30  pthread_mutex_unlock(&mhMutex);
31  }
32 
33 private:
34  pthread_mutexattr_t mhMutexAttr;
35  pthread_mutex_t mhMutex;
36 
37  friend class tcCondition;
38 };
39 
41 {
42 public:
44  :
45  mpMutex(apMutex)
46  {
47  mpMutex->lock();
48  }
49 
51  {
52  mpMutex->unlock();
53  }
54 
55 private:
56  tcMutex *mpMutex;
57 };
58 
59 #endif // MUTEX_H
tcMutexLocker::~tcMutexLocker
~tcMutexLocker()
Definition: Mutex.h:50
Types.h
tcMutex::tcMutex
tcMutex(bool recursive=true)
Definition: Mutex.cpp:3
tcMutex::unlock
void unlock()
Definition: Mutex.h:28
tcMutexLocker::tcMutexLocker
tcMutexLocker(tcMutex *apMutex)
Definition: Mutex.h:43
tcMutex::~tcMutex
~tcMutex()
Definition: Mutex.cpp:14
tcMutexLocker
Definition: Mutex.h:40
tcCondition
Definition: Condition.h:8
tcMutex
Definition: Mutex.h:11
tcMutex::lock
void lock()
Definition: Mutex.h:18