]> git.vomp.tv Git - vompclient-marten.git/blob - threadwin.h
Fix bug in demuxer widescreen signaling
[vompclient-marten.git] / threadwin.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #ifndef THREADWIN_H
22 #define THREADWIN_H
23
24
25 #define _WIN32_WINNT 0x501
26 #include <winsock2.h>
27 #include <windows.h>
28 typedef struct timespec
29 {
30   long tv_sec; /* seconds */
31   long tv_nsec; /* nanoseconds */
32 } timespec;
33 #define WINDOWS_TIME_BASE_OFFSET 116444736000000000
34
35 #include "thread.h"
36
37 class ThreadWin : public Thread
38 {
39   protected:
40     // Override this method in derived classes
41         
42     virtual void threadMethod()=0;
43     virtual void threadPostStopCleanup()=0;
44           ThreadWin();
45      ~ThreadWin();
46
47     // Methods to use from outside the thread
48     int threadStart();    // start the thread. threadMethod() will be called in derived class
49     void threadStop();    // stop the thread nicely. thread will be stopped when it next calls threadCheckExit()
50     void threadCancel();  // stop thread immediately. thread will be stopped at the next cancellation point
51     void threadSignal();  // releases a thread that has called threadWaitForSignal
52     void threadSignalNoLock();  // same as above but without locking guarantees. probably not a good idea.
53    
54
55     // Methods to use from inside the thread
56     void threadSetKillable();    // allows threadCancel() to work
57     void threadCheckExit();      // terminates thread if threadStop() has been called
58     void threadWaitForSignal();  // pauses thread until threadSignal() is called
59     void threadWaitForSignalTimed(struct timespec*);  // pauses thread until threadSignal() is called or timer expires
60     void threadLock();           // locks the mutex used for internal cond/signal stuff
61     void threadUnlock();         // unlocks.
62
63     // Internal bits and pieces
64
65 //  private: // TODO: make these private again when dvbsubtitles.cc
66              // no longer needs direct access.
67     HANDLE pthread;
68     HANDLE threadCondMutex;
69     HANDLE threadCond;
70     HANDLE threadKillable;
71     DWORD threadId;
72   
73   public:
74     void threadSuicide();        // Self termination
75     static unsigned int thisThreadID();
76     unsigned int getThreadID(); // returns the ID of this thread
77 };
78
79 #endif
80