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

#include <Sync.h>

Collaboration diagram for Condition:

Public Member Functions

 Condition (Mutex &mutex)
 
 ~Condition ()
 
bool IsOk () const
 
int Wait ()
 
int Signal ()
 
int Broadcast ()
 

Private Attributes

Mutexm_mutex
 
pthread_cond_t m_cond
 
bool m_isOk
 

Detailed Description

Definition at line 47 of file Sync.h.

Constructor & Destructor Documentation

Condition ( Mutex mutex)

Definition at line 116 of file Sync.C.

References m_cond, and m_isOk.

117 : m_mutex(mutex)
118 {
119  int err = pthread_cond_init(&m_cond, NULL);
120 
121  m_isOk = (err == 0);
122 
123  if (!m_isOk) {
124  std::cerr << "Condition::Condition(): pthread_cond_init() returned " << err
125  << std::endl;
126  }
127 }
Mutex & m_mutex
Definition: Sync.h:60
pthread_cond_t m_cond
Definition: Sync.h:61
bool m_isOk
Definition: Sync.h:62
~Condition ( )

Definition at line 129 of file Sync.C.

References COMMPI_Initialized(), m_cond, and m_isOk.

130 {
131  if (m_isOk) {
132  int err = pthread_cond_destroy(&m_cond);
133  if (err != 0 && !COMMPI_Initialized()) {
134  std::cerr << "Condition::~Condition(): pthread_cond_destroy() returned "
135  << err << std::endl;
136  }
137  }
138 }
pthread_cond_t m_cond
Definition: Sync.h:61
int COMMPI_Initialized()
Definition: commpi.h:168
bool m_isOk
Definition: Sync.h:62

Here is the call graph for this function:

Member Function Documentation

int Broadcast ( )

Definition at line 160 of file Sync.C.

References m_cond.

161 {
162  int err = pthread_cond_broadcast(&m_cond);
163  if (err != 0)
164  std::cerr << "Condition::Broadcast(): pthread_cond_broadcast() returned "
165  << err << std::endl;
166 
167  return err;
168 }
pthread_cond_t m_cond
Definition: Sync.h:61
bool IsOk ( ) const
inline

Definition at line 53 of file Sync.h.

References Mutex::IsOk(), m_isOk, and m_mutex.

Referenced by Semaphore::Semaphore().

53 { return (m_isOk && m_mutex.IsOk()); }
bool IsOk() const
Definition: Sync.h:34
Mutex & m_mutex
Definition: Sync.h:60
bool m_isOk
Definition: Sync.h:62

Here is the call graph for this function:

Here is the caller graph for this function:

int Signal ( )

Definition at line 150 of file Sync.C.

References m_cond.

Referenced by Semaphore::Post().

151 {
152  int err = pthread_cond_signal(&m_cond);
153  if (err != 0)
154  std::cerr << "Condition::Signal(): pthread_cond_signal() returned " << err
155  << std::endl;
156 
157  return err;
158 }
pthread_cond_t m_cond
Definition: Sync.h:61

Here is the caller graph for this function:

int Wait ( )

Definition at line 140 of file Sync.C.

References m_cond, Mutex::m_mutex, and m_mutex.

Referenced by Semaphore::Wait().

141 {
142  int err = pthread_cond_wait(&m_cond, &(m_mutex.m_mutex));
143  if (err != 0)
144  std::cerr << "Condition::Wait(): pthread_cond_wait() returned " << err
145  << std::endl;
146 
147  return err;
148 }
Mutex & m_mutex
Definition: Sync.h:60
pthread_cond_t m_cond
Definition: Sync.h:61
pthread_mutex_t m_mutex
Definition: Sync.h:43

Here is the caller graph for this function:

Member Data Documentation

pthread_cond_t m_cond
private

Definition at line 61 of file Sync.h.

Referenced by Broadcast(), Condition(), Signal(), Wait(), and ~Condition().

bool m_isOk
private

Definition at line 62 of file Sync.h.

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

Mutex& m_mutex
private

Definition at line 60 of file Sync.h.

Referenced by IsOk(), and Wait().


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