1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2003 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
41 #if defined (OSG_USE_PTHREADS)
43 /*------------------------------- CondVar ---------------------------------*/
46 void PThreadCondVarBase::acquire(void)
48 pthread_mutex_lock(&(_pLowLevelLock));
52 void PThreadCondVarBase::release(void)
54 pthread_mutex_unlock(&(_pLowLevelLock));
58 bool PThreadCondVarBase::request(void)
60 return (pthread_mutex_trylock(&(_pLowLevelLock)) != EBUSY);
64 void PThreadCondVarBase::signal()
66 pthread_cond_signal(&(_pLowLevelCondVar));
70 void PThreadCondVarBase::broadcast()
72 pthread_cond_broadcast(&(_pLowLevelCondVar));
75 #endif /* OSG_USE_PTHREADS */
78 #if defined (OSG_USE_SPROC)
80 /*------------------------------- CondVar ---------------------------------*/
83 void SprocCondVarBase::acquire(void)
85 #ifdef OSG_SPROC_USE_LOCK
86 if(_pLowLevelLock != NULL)
87 ussetlock(_pLowLevelLock);
89 if(_pLowLevelSema != NULL)
90 uspsema(_pLowLevelSema);
95 void SprocCondVarBase::release(void)
97 #ifdef OSG_SPROC_USE_LOCK
98 if(_pLowLevelLock != NULL)
99 usunsetlock(_pLowLevelLock);
101 if(_pLowLevelSema != NULL)
102 usvsema(_pLowLevelSema);
107 bool SprocCondVarBase::request(void)
109 bool returnValue = false;
112 #ifdef OSG_SPROC_USE_LOCK
113 if(_pLowLevelLock != NULL)
114 rc = uscsetlock(_pLowLevelLock, 0);
116 if(_pLowLevelSema != NULL)
117 rc = uscpsema(_pLowLevelSema);
120 returnValue = (rc == 1);
126 bool SprocCondVarBase::wait(const Int32 timeToWait)
128 OSG_ASSERT(false && "Not implemented.");
132 void SprocCondVarBase::signal()
134 OSG_ASSERT(false && "Not implemented.");
138 void SprocCondVarBase::broadcast()
140 OSG_ASSERT(false && "Not implemented.");
143 #endif /* OSG_USE_SPROC */
146 #if defined (OSG_USE_WINTHREADS)
148 /*------------------------------- CondVar ---------------------------------*/
151 void WinThreadCondVarBase::acquire(void)
153 #if defined(OSG_GV_BETA) && defined(OSG_DBG_LCK)
154 fprintf(stderr, "CondVar::acquire %p\n", this);
157 WaitForSingleObject(_pMutex, INFINITE);
161 void WinThreadCondVarBase::release(void)
163 #if defined(OSG_GV_BETA) && defined(OSG_DBG_LCK)
164 fprintf(stderr, "CondVar::release %p\n", this);
167 ReleaseMutex(_pMutex);
171 bool WinThreadCondVarBase::request(void)
174 rc = WaitForSingleObject(_pMutex, 0);
176 if(rc == WAIT_OBJECT_0)
186 #endif /* OSG_USE_WINTHREADS */
192 CondVar::ObjTransitPtr CondVar::create(void)
194 return CondVar::get(NULL, false);
198 const MPCondVarType &CondVar::getClassType(void)
203 /*------------------------------- CondVar ---------------------------------*/
206 void CondVar::acquire(void)
208 Inherited::acquire();
212 void CondVar::release(void)
214 Inherited::release();
218 bool CondVar::request(void)
220 return Inherited::request();
224 bool CondVar::wait(const Int32 timeToWait)
226 return Inherited::wait(timeToWait);
230 void CondVar::signal(void)
232 return Inherited::signal();
236 void CondVar::broadcast(void)
238 return Inherited::broadcast();
241 /*------------------------------ CondVar ----------------------------------*/
243 #if defined(OSG_WIN32_ICL) || defined(OSG_LINUX_ICC)
244 #pragma warning (error : 171)