changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / Threading / OSGCondVar.inl
blobcf65cfc45b8b70237a6a2ca1676db4e03d0184be
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *           Copyright (C) 2003 by the OpenSG Forum                          *
6  *                                                                           *
7  *                            www.opensg.org                                 *
8  *                                                                           *
9  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
10  *                                                                           *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13  *                                License                                    *
14  *                                                                           *
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.                               *
18  *                                                                           *
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.                          *
23  *                                                                           *
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.                 *
27  *                                                                           *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30  *                                Changes                                    *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35  *                                                                           *
36  *                                                                           *
37 \*---------------------------------------------------------------------------*/
39 OSG_BEGIN_NAMESPACE
41 #if defined (OSG_USE_PTHREADS)
43 /*------------------------------- CondVar ---------------------------------*/
45 inline
46 void PThreadCondVarBase::acquire(void)
48     pthread_mutex_lock(&(_pLowLevelLock));
51 inline
52 void PThreadCondVarBase::release(void)
54     pthread_mutex_unlock(&(_pLowLevelLock));
57 inline
58 bool PThreadCondVarBase::request(void)
60     return (pthread_mutex_trylock(&(_pLowLevelLock)) != EBUSY);
63 inline
64 void PThreadCondVarBase::signal()
66     pthread_cond_signal(&(_pLowLevelCondVar));
69 inline
70 void PThreadCondVarBase::broadcast()
72     pthread_cond_broadcast(&(_pLowLevelCondVar));
75 #endif /* OSG_USE_PTHREADS */
78 #if defined (OSG_USE_SPROC)
80 /*------------------------------- CondVar ---------------------------------*/
82 inline
83 void SprocCondVarBase::acquire(void)
85 #ifdef OSG_SPROC_USE_LOCK
86     if(_pLowLevelLock != NULL)
87         ussetlock(_pLowLevelLock);
88 #else
89     if(_pLowLevelSema != NULL)
90         uspsema(_pLowLevelSema);
91 #endif
94 inline
95 void SprocCondVarBase::release(void)
97 #ifdef OSG_SPROC_USE_LOCK
98     if(_pLowLevelLock != NULL)
99         usunsetlock(_pLowLevelLock);
100 #else
101     if(_pLowLevelSema != NULL)
102         usvsema(_pLowLevelSema);
103 #endif
106 inline
107 bool SprocCondVarBase::request(void)
109     bool  returnValue = false;
110     Int32 rc          = 0;
112 #ifdef OSG_SPROC_USE_LOCK
113     if(_pLowLevelLock != NULL)
114         rc = uscsetlock(_pLowLevelLock, 0);
115 #else
116     if(_pLowLevelSema != NULL)
117         rc = uscpsema(_pLowLevelSema);
118 #endif
120     returnValue = (rc == 1);
122     return returnValue;
125 inline
126 bool SprocCondVarBase::wait(const Int32 timeToWait)
128    OSG_ASSERT(false && "Not implemented.");
131 inline
132 void SprocCondVarBase::signal()
134    OSG_ASSERT(false && "Not implemented.");
137 inline
138 void SprocCondVarBase::broadcast()
140    OSG_ASSERT(false && "Not implemented.");
143 #endif /* OSG_USE_SPROC */
146 #if defined (OSG_USE_WINTHREADS)
148 /*------------------------------- CondVar ---------------------------------*/
150 inline
151 void WinThreadCondVarBase::acquire(void)
153 #if defined(OSG_GV_BETA) && defined(OSG_DBG_LCK)
154     fprintf(stderr, "CondVar::acquire %p\n", this);
155 #endif
157     WaitForSingleObject(_pMutex, INFINITE);
160 inline
161 void WinThreadCondVarBase::release(void)
163 #if defined(OSG_GV_BETA) && defined(OSG_DBG_LCK)
164     fprintf(stderr, "CondVar::release %p\n", this);
165 #endif
167     ReleaseMutex(_pMutex);
170 inline
171 bool WinThreadCondVarBase::request(void)
173     DWORD rc;
174     rc = WaitForSingleObject(_pMutex, 0);
176     if(rc == WAIT_OBJECT_0)
177     {
178         return true;
179     }
180     else
181     {
182         return false;
183     }
186 #endif /* OSG_USE_WINTHREADS */
191 inline
192 CondVar::ObjTransitPtr CondVar::create(void)
194     return CondVar::get(NULL, false);
197 inline
198 const MPCondVarType &CondVar::getClassType(void)
200     return _type;
203 /*------------------------------- CondVar ---------------------------------*/
205 inline
206 void CondVar::acquire(void)
208     Inherited::acquire();
211 inline
212 void CondVar::release(void)
214     Inherited::release();
217 inline
218 bool CondVar::request(void)
220     return Inherited::request();
223 inline
224 bool CondVar::wait(const Int32 timeToWait)
226     return Inherited::wait(timeToWait);
229 inline
230 void CondVar::signal(void)
232     return Inherited::signal();
235 inline
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)
245 #endif
247 OSG_END_NAMESPACE