FRIBParallelanalysis  1.0
FrameworkforMPIParalleldataanalysisatFRIB
CTCLConditionVariable.h
1 #ifndef CTCLCONDITIONVARIABLE_H
2 #define CTCLCONDITIONVARIABLE_H
3 /*
4  This software is Copyright by the Board of Trustees of Michigan
5  State University (c) Copyright 2005.
6 
7  You may use this software under the terms of the GNU public license
8  (GPL). The terms of this license are described at:
9 
10  http://www.gnu.org/licenses/gpl.txt
11 
12  Author:
13  Ron Fox
14  NSCL
15  Michigan State University
16  East Lansing, MI 48824-1321
17 */
18 
19 // Since it seems that I can't get Tcl_Mutex's to work properly (they must
20 // somehow but I can't figure out what I did wrong), and that implies that
21 // condition variables won't work either, I'm grabbing the ConditionVariable
22 // code from NSCLDAQ/main/base/thread and aliasing class names to make it look
23 // like these are actually in Tcl libraries.
24 
25 
26 #include <pthread.h>
27 #include <time.h>
28 
29 
30 class CMutex;
31 
37 {
38  pthread_condattr_t m_attributes;
39 
42 
43  void setShared();
44  void setUnshared();
45  bool isShared();
46 
47  static void throwifbad(int status, const char* msg);
48 };
49 
55 {
56 public:
57  pthread_cond_t m_condition;
58 
59 public:
61  CConditionVariable(pthread_condattr_t& attr);
63  virtual ~CConditionVariable();
64 private:
66  CConditionVariable& operator=(const CConditionVariable& rhs);
67  int operator==(const CConditionVariable& rhs) const;
68  int operator!=(const CConditionVariable& rhs) const;
69 
70  // Synchronization operations:
71 
72 public:
73  void signal();
74  void broadcast();
75 
76  bool timedwait(CMutex& mutex,
77  const struct timespec* abstime);
78  bool timedwait(pthread_mutex_t* mutex,
79  const struct timespec* abstime);
80 
81  bool timedwait(CMutex& mutex,
82  int milliseconds);
83  bool timedwait(pthread_mutex_t* mutex,
84  int milliseconds);
85 
86  void wait(CMutex& mutex);
87  void wait(pthread_mutex_t* mutex);
88 
89 
90 private:
91  void create(pthread_condattr_t* pAttributes);
92  struct timespec timeout(int milliseconds);
93 
94 
95 };
96 // Alias trick:
97 
100 #endif
Definition: CTCLConditionVariable.h:54
Definition: CTCLMutex.h:54
void setShared()
Definition: CTCLConditionVariable.cpp:46
bool isShared()
Definition: CTCLConditionVariable.cpp:68
Definition: CTCLConditionVariable.h:36
void setUnshared()
Definition: CTCLConditionVariable.cpp:56