solver
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RtMutex.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <pthread.h>
13 
14 namespace rt_solver {
15 
16  struct RtMutex
17  {
18  public:
19  typedef pthread_mutex_t MutexType;
20 
21  RtMutex() { init(); }
22  ~RtMutex() { destroy(); }
23 
24  inline int lock() { return pthread_mutex_lock(&m_); }
25  inline int unlock() { return pthread_mutex_unlock(&m_); }
26  inline int trylock() { return pthread_mutex_trylock(&m_); }
27 
28  MutexType m_;
29 
30  private:
31  inline int init() { return pthread_mutex_init(&m_, NULL); }
32  inline int destroy() { return pthread_mutex_destroy(&m_); }
33  };
34 
35 
36  struct RtCond
37  {
38  public:
39  typedef pthread_cond_t CondType;
40 
41  RtCond() { init(); }
42  ~RtCond() { destroy(); }
43 
44  inline int signal() { return pthread_cond_signal(&c_); }
45  inline int broadcast() { return pthread_cond_broadcast(&c_); }
46  inline int wait(RtMutex& mutex) { return pthread_cond_wait(&c_, &mutex.m_); }
47 
48  CondType c_;
49 
50  private:
51  inline int init() { return pthread_cond_init(&c_, NULL); }
52  inline int destroy() { return pthread_cond_destroy(&c_); }
53  };
54 
55 }
Definition: Var.hpp:14
Definition: RtMutex.hpp:16
Definition: RtMutex.hpp:36