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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "threadpandroid.h"
24 // Undeclared functions, only for use in this file to start the thread
25 void threadPAndroidInternalStart(void *arg)
27 // I don't want signals
30 pthread_sigmask(SIG_BLOCK, &sigs, NULL);
32 Thread *t = (Thread *)arg;
33 t->threadInternalStart2();
36 int ThreadPAndroid ::threadStart()
38 pthread_cond_init(&threadCond, NULL);
39 pthread_cond_init(&threadKillable, NULL);
40 pthread_mutex_init(&threadCondMutex, NULL);
44 if (pthread_create(&pthread, NULL, (void*(*)(void*))threadPAndroidInternalStart, (void *)this) == -1) return 0;
48 void ThreadPAndroid ::threadStop()
51 // Signal thread here in case it's waiting
53 pthread_join(pthread, NULL);
54 this->threadPostStopCleanup();
58 void ThreadPAndroid ::threadCancel()
62 if (killable) pthread_cond_wait(&threadKillable,&threadCondMutex);
63 // pthread_cancel(pthread);
64 pthread_join(pthread, NULL);
65 this->threadPostStopCleanup();
70 void ThreadPAndroid ::threadCheckExit()
73 pthread_cond_signal(&threadKillable);
78 void ThreadPAndroid ::threadLock()
80 pthread_mutex_lock(&threadCondMutex);
83 void ThreadPAndroid ::threadUnlock()
85 pthread_mutex_unlock(&threadCondMutex);
88 void ThreadPAndroid ::threadSignal()
90 pthread_mutex_lock(&threadCondMutex);
91 pthread_cond_signal(&threadCond);
92 pthread_mutex_unlock(&threadCondMutex);
95 void ThreadPAndroid ::threadSignalNoLock()
97 pthread_cond_signal(&threadCond);
100 void ThreadPAndroid ::threadWaitForSignal()
102 pthread_cond_wait(&threadCond, &threadCondMutex);
105 void ThreadPAndroid ::threadWaitForSignalTimed(struct timespec* ts)
107 pthread_cond_timedwait(&threadCond, &threadCondMutex, ts);
110 void ThreadPAndroid ::threadSetKillable()
112 //pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
113 //pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
115 pthread_cond_signal(&threadKillable);
119 pthread_t ThreadPAndroid ::getThreadID() // returns the ID of this thread
126 void ThreadPAndroid ::threadSuicide()
128 if(!pthread_detach(pthread_self()))
131 if(!pthread_detach(pthread_self()))
134 pthread_detach(pthread_self());
141 pthread_t ThreadPAndroid ::thisThreadID() // returns the ID of the calling thread
143 return pthread_self();