Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mutex Class Reference

#include <Sync.h>

Public Member Functions

 Mutex ()
 
 ~Mutex ()
 
bool IsOk () const
 
int Lock ()
 
int TryLock ()
 
int Unlock ()
 

Private Attributes

pthread_mutex_t m_mutex
 
bool m_isOk
 

Friends

class Condition
 

Detailed Description

Definition at line 28 of file Sync.h.

Constructor & Destructor Documentation

Mutex ( )

Definition at line 29 of file Sync.C.

References m_isOk, and m_mutex.

30 {
31  int err = pthread_mutex_init(&m_mutex, NULL);
32  m_isOk = (err == 0);
33  if (!m_isOk) {
34  std::cerr << "Mutex::Mutex(): pthread_mutex_init() returned " << err
35  << std::endl;
36  }
37 }
bool m_isOk
Definition: Sync.h:44
pthread_mutex_t m_mutex
Definition: Sync.h:43
~Mutex ( )

Definition at line 39 of file Sync.C.

References COMMPI_Initialized(), m_isOk, and m_mutex.

40 {
41  if (m_isOk) {
42  int err = pthread_mutex_destroy(&m_mutex);
43  if (err != 0 && !COMMPI_Initialized()) {
44  std::cerr << "Mutex::~Mutex(): pthread_mutex_destroy() returned " << err
45  << std::endl;
46  }
47  }
48 }
bool m_isOk
Definition: Sync.h:44
pthread_mutex_t m_mutex
Definition: Sync.h:43
int COMMPI_Initialized()
Definition: commpi.h:168

Here is the call graph for this function:

Member Function Documentation

bool IsOk ( ) const
inline

Definition at line 34 of file Sync.h.

References m_isOk.

Referenced by Condition::IsOk(), and Semaphore::Semaphore().

34 { return m_isOk; }
bool m_isOk
Definition: Sync.h:44

Here is the caller graph for this function:

int Lock ( )

Definition at line 50 of file Sync.C.

References m_mutex.

Referenced by Semaphore::Post(), Semaphore::TryWait(), and Semaphore::Wait().

51 {
52  int err = pthread_mutex_lock(&m_mutex);
53  switch (err) {
54  case 0:
55  break;
56 
57  case EDEADLK:
58  std::cerr << "Mutex::Lock(): mutex deadlock prevented." << std::endl;
59  break;
60 
61  case EINVAL:
62  std::cerr << "Mutex::Lock(): mutex not initialized." << std::endl;
63  break;
64 
65  default:
66  std::cerr << "Mutex::Lock(): pthread_mutex_lock() returned " << err
67  << std::endl;
68  break;
69  }
70 
71  return err;
72 }
pthread_mutex_t m_mutex
Definition: Sync.h:43

Here is the caller graph for this function:

int TryLock ( )

Definition at line 74 of file Sync.C.

References m_mutex.

75 {
76  int err = pthread_mutex_trylock(&m_mutex);
77  switch (err) {
78  case 0:
79  case EBUSY:
80  break;
81 
82  case EINVAL:
83  std::cerr << "Mutex::TryLock(): mutex not initialized." << std::endl;
84  break;
85 
86  default:
87  std::cerr << "Mutex::TryLock(): pthread_mutex_trylock() returned "
88  << err << std::endl;
89  break;
90  }
91 
92  return err;
93 }
pthread_mutex_t m_mutex
Definition: Sync.h:43
int Unlock ( )

Definition at line 95 of file Sync.C.

References m_mutex.

Referenced by Semaphore::Post(), Semaphore::TryWait(), and Semaphore::Wait().

96 {
97  int err = pthread_mutex_unlock(&m_mutex);
98  switch (err) {
99  case 0:
100  case EPERM:
101  break;
102 
103  case EINVAL:
104  std::cerr << "Mutex::Unlock(): mutex not initialized." << std::endl;
105  break;
106 
107  default:
108  std::cerr << "Mutex::Unlock(): pthread_mutex_unlock() returned " << err
109  << std::endl;
110  break;
111  }
112 
113  return err;
114 }
pthread_mutex_t m_mutex
Definition: Sync.h:43

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class Condition
friend

Definition at line 40 of file Sync.h.

Member Data Documentation

bool m_isOk
private

Definition at line 44 of file Sync.h.

Referenced by IsOk(), Mutex(), and ~Mutex().

pthread_mutex_t m_mutex
private

Definition at line 43 of file Sync.h.

Referenced by Lock(), Mutex(), TryLock(), Unlock(), Condition::Wait(), and ~Mutex().


The documentation for this class was generated from the following files: