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 \*---------------------------------------------------------------------------*/
42 bool BaseThreadCommonBase::isInitialized(void)
48 #if defined (OSG_USE_PTHREADS)
50 /*---------------------------- Blocking -----------------------------------*/
53 void BasePThreadBase::block(void)
55 pthread_mutex_lock (_pBlockMutex);
56 pthread_cond_wait (_pBlockCond, _pBlockMutex);
57 pthread_mutex_unlock(_pBlockMutex);
61 void BasePThreadBase::unblock(void)
63 pthread_cond_broadcast(_pBlockCond);
66 /*------------------------------ Helper -----------------------------------*/
69 bool BasePThreadBase::exists(void)
75 void BasePThreadBase::terminate(void)
77 if(_pThreadDesc != NULL)
78 pthread_cancel(*_pThreadDesc);
82 void BasePThreadBase::kill(void)
84 if(_pThreadDesc != NULL)
85 pthread_cancel(*_pThreadDesc);
89 #endif /* OSG_USE_PTHREADS */
94 #if defined (OSG_USE_SPROC)
96 /*------------------------------- Get -------------------------------------*/
99 BaseThread *BaseSprocBase::getCurrent(void)
101 return ((ProcessData *) PRDA->usr_prda.fill)->_pThread;
104 /*---------------------------- Blocking -----------------------------------*/
107 void BaseSprocBase::block(void)
113 void BaseSprocBase::unblock(void)
118 /*------------------------------ Helper -----------------------------------*/
121 bool BaseSprocBase::exists(void)
123 bool returnValue = false;
125 returnValue = (prctl(PR_ISBLOCKED, _pid) != -1);
132 void BaseSprocBase::terminate(void)
134 ::kill(_pid, SIGTERM);
138 void BaseSprocBase::kill(void)
140 ::kill(_pid, SIGKILL);
143 #endif /* OSG_USE_SPROC */
148 #if defined (OSG_USE_WINTHREADS)
150 /*----------------------------- Blocking ----------------------------------*/
153 void BaseWinThreadBase::block(void)
155 SuspendThread(_pThreadHandle);
159 void BaseWinThreadBase::unblock(void)
161 ResumeThread(_pExternalHandle);
164 /*----------------------------- Helper ------------------------------------*/
167 bool BaseWinThreadBase::exists(void)
169 bool returnValue = false;
172 if(BaseWinThreadBase::getCurrentInternal() == this)
174 GetExitCodeThread( _pThreadHandle,
179 GetExitCodeThread( _pExternalHandle,
183 returnValue = (rc == STILL_ACTIVE);
190 void BaseWinThreadBase::terminate(void)
192 if(BaseWinThreadBase::getCurrentInternal() == this)
194 TerminateThread(_pThreadHandle, 0);
198 TerminateThread(_pExternalHandle, 0);
203 void BaseWinThreadBase::kill(void)
205 if(BaseWinThreadBase::getCurrentInternal() == this)
207 TerminateThread(_pThreadHandle, 0);
211 TerminateThread(_pExternalHandle, 0);
215 #endif /* OSG_USE_WINTHREADS */
219 BaseThread::ObjTransitPtr BaseThread::create(void)
221 return BaseThread::get(NULL, false);
225 const MPThreadType &BaseThread::getClassType(void)
230 /*------------------------------- Get -------------------------------------*/
233 BaseThread *BaseThread::getCurrent(void)
235 return Inherited::getCurrent();
238 /*------------------------------ Join -------------------------------------*/
241 void BaseThread::join(BaseThread *pThread)
243 Inherited::join(pThread);
246 /*------------------------------- Run -------------------------------------*/
250 void BaseThread::run(void)
252 Inherited::runFunction(runWorkProc, this);
256 bool BaseThread::runFunction(ThreadFuncF fThreadFunc,
259 return Inherited::runFunction(fThreadFunc, pThreadArg);
262 /*----------------------------- Blocking ----------------------------------*/
265 void BaseThread::block(void)
271 void BaseThread::unblock(void)
273 Inherited::unblock();
276 /*----------------------------- Helper ------------------------------------*/
279 bool BaseThread::exists(void)
281 return Inherited::exists();
285 void BaseThread::terminate(void)
287 Inherited::terminate();
291 void BaseThread::kill(void)