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
21 #include "threadwin.h"
23 // Undeclared functions, only for use in this file to start the thread
24 DWORD WINAPI threadInternalStart(void *arg)
26 Thread *t = (Thread *)arg;
27 t->threadInternalStart2();
31 int ThreadP::threadStart()
33 threadCond = CreateEvent(NULL,FALSE,FALSE,NULL);
34 if (threadCond == NULL) return 0;
35 threadCondMutex = CreateMutex(NULL,TRUE,NULL);
36 if (threadCondMutex == NULL)
38 CloseHandle(threadCond);
44 pthread = CreateThread(NULL, 0, threadInternalStart, (void*)this,0, &threadId);
47 CloseHandle(threadCond);
48 CloseHandle(threadCondMutex);
54 void ThreadP::threadStop()
57 // Signal thread here in case it's waiting
59 WaitForSingleObject(pthread, INFINITE);
60 this->threadPostStopCleanup();
63 void ThreadP::threadCancel()
66 TerminateThread(pthread, 0);
67 WaitForSingleObject(pthread, INFINITE);
68 this->threadPostStopCleanup();
71 void ThreadP::threadCheckExit()
73 if (!threadActive) ExitThread(NULL);
76 void ThreadP::threadLock()
78 WaitForSingleObject(threadCondMutex, INFINITE);
81 void ThreadP::threadUnlock()
83 ReleaseMutex(threadCondMutex);
86 void ThreadP::threadSignal()
88 WaitForSingleObject(threadCondMutex, INFINITE);
90 ReleaseMutex(threadCondMutex);
93 void ThreadP::threadSignalNoLock()
98 void ThreadP::threadWaitForSignal()
100 WaitForSingleObject(threadCond,INFINITE);
103 void ThreadP::threadWaitForSignalTimed(struct timespec* ts)
105 HANDLE handles[2] ={threadCond, NULL};
106 LARGE_INTEGER duration;
107 duration.QuadPart=ts->tv_sec*1000*1000*10+ts->tv_nsec/100;
109 handles[1]=CreateWaitableTimer(NULL,TRUE,NULL);
110 /* SetWaitableTimer(handles[1], &duration, 0, NULL, NULL, 0);
111 WaitForMultipleObject(2,handles,INFINITE);*/
112 CloseHandle(handles[1]);
115 void ThreadP::threadSetKillable()
117 //WIN32:Ignore or use a separate Event Object to simulate this