Panda3D
 All Classes Functions Variables Enumerations
conditionVarPosixImpl.I
1 // Filename: conditionVarPosixImpl.I
2 // Created by: drose (10Feb06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ConditionVarPosixImpl::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ConditionVarPosixImpl::
22 ConditionVarPosixImpl(MutexPosixImpl &mutex) :
23  _mutex(mutex)
24 {
25  TAU_PROFILE("ConditionVarPosixImpl::ConditionVarPosixImpl()", " ", TAU_USER);
26  int result = pthread_cond_init(&_cvar, NULL);
27  nassertv(result == 0);
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: ConditionVarPosixImpl::Destructor
32 // Access: Public
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 INLINE ConditionVarPosixImpl::
36 ~ConditionVarPosixImpl() {
37  TAU_PROFILE("ConditionVarPosixImpl::~ConditionVarPosixImpl()", " ", TAU_USER);
38  int result = pthread_cond_destroy(&_cvar);
39  nassertv(result == 0);
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: ConditionVarPosixImpl::wait
44 // Access: Public
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 INLINE void ConditionVarPosixImpl::
48 wait() {
49  TAU_PROFILE("ConditionVarPosixImpl::wait()", " ", TAU_USER);
50  int result = pthread_cond_wait(&_cvar, &_mutex._lock);
51 #ifndef NDEBUG
52  if (result != 0) {
53  pipeline_cat.error()
54  << "Unexpected error " << result << " from pthread_cond_wait()\n";
55  }
56 #endif
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: ConditionVarPosixImpl::notify
61 // Access: Public
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 INLINE void ConditionVarPosixImpl::
65 notify() {
66  TAU_PROFILE("ConditionVarPosixImpl::notify()", " ", TAU_USER);
67  int result = pthread_cond_signal(&_cvar);
68  nassertv(result == 0);
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: ConditionVarPosixImpl::notify_all
73 // Access: Public
74 // Description:
75 ////////////////////////////////////////////////////////////////////
76 INLINE void ConditionVarPosixImpl::
77 notify_all() {
78  TAU_PROFILE("ConditionVarPosixImpl::notify()", " ", TAU_USER);
79  int result = pthread_cond_broadcast(&_cvar);
80  nassertv(result == 0);
81 }