2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 // Undeclared functions, only for use in this file to start the thread
24 void threadInternalStart(void *arg)
26 // I don't want signals
29 pthread_sigmask(SIG_BLOCK, &sigs, NULL);
31 Thread *t = (Thread *)arg;
32 t->threadInternalStart2();
35 void Thread::threadInternalStart2()
40 int Thread::threadStart()
42 pthread_cond_init(&threadCond, NULL);
43 pthread_mutex_init(&threadCondMutex, NULL);
46 if (pthread_create(&pthread, NULL, (void*(*)(void*))threadInternalStart, (void *)this) == -1) return 0;
50 void Thread::threadStop()
53 // Signal thread here in case it's waiting
55 pthread_join(pthread, NULL);
56 this->threadPostStopCleanup();
59 void Thread::threadCancel()
62 pthread_cancel(pthread);
63 pthread_join(pthread, NULL);
64 this->threadPostStopCleanup();
67 void Thread::threadCheckExit()
69 if (!threadActive) pthread_exit(NULL);
72 char Thread::threadIsActive()
77 void Thread::threadLock()
79 pthread_mutex_lock(&threadCondMutex);
82 void Thread::threadUnlock()
84 pthread_mutex_unlock(&threadCondMutex);
87 void Thread::threadSignal()
89 pthread_mutex_lock(&threadCondMutex);
90 pthread_cond_signal(&threadCond);
91 pthread_mutex_unlock(&threadCondMutex);
94 void Thread::threadSignalNoLock()
96 pthread_cond_signal(&threadCond);
99 void Thread::threadWaitForSignal()
101 pthread_cond_wait(&threadCond, &threadCondMutex);
104 void Thread::threadWaitForSignalTimed(struct timespec* ts)
106 pthread_cond_timedwait(&threadCond, &threadCondMutex, ts);
109 void Thread::threadSetKillable()
111 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
112 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);