1 | /*
|
---|
2 | * synergy -- mouse and keyboard sharing utility
|
---|
3 | * Copyright (C) 2002 Chris Schoeneman
|
---|
4 | *
|
---|
5 | * This package is free software you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU General Public License
|
---|
7 | * found in the file COPYING that should have accompanied this file.
|
---|
8 | *
|
---|
9 | * This package is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 | */
|
---|
14 |
|
---|
15 | #ifndef CARCHMULTITHREADWINDOWS_H
|
---|
16 | #define CARCHMULTITHREADWINDOWS_H
|
---|
17 |
|
---|
18 | #define WIN32_LEAN_AND_MEAN
|
---|
19 |
|
---|
20 | #include "IArchMultithread.h"
|
---|
21 | #include "stdlist.h"
|
---|
22 | #include <windows.h>
|
---|
23 |
|
---|
24 | #define ARCH_MULTITHREAD CArchMultithreadWindows
|
---|
25 |
|
---|
26 | class CArchCondImpl {
|
---|
27 | public:
|
---|
28 | enum { kSignal = 0, kBroadcast };
|
---|
29 |
|
---|
30 | HANDLE m_events[2];
|
---|
31 | mutable int m_waitCount;
|
---|
32 | CArchMutex m_waitCountMutex;
|
---|
33 | };
|
---|
34 |
|
---|
35 | class CArchMutexImpl {
|
---|
36 | public:
|
---|
37 | CRITICAL_SECTION m_mutex;
|
---|
38 | };
|
---|
39 |
|
---|
40 | //! Win32 implementation of IArchMultithread
|
---|
41 | class CArchMultithreadWindows : public IArchMultithread {
|
---|
42 | public:
|
---|
43 | CArchMultithreadWindows();
|
---|
44 | virtual ~CArchMultithreadWindows();
|
---|
45 |
|
---|
46 | //! @name manipulators
|
---|
47 | //@{
|
---|
48 |
|
---|
49 | void setNetworkDataForCurrentThread(void*);
|
---|
50 |
|
---|
51 | //@}
|
---|
52 | //! @name accessors
|
---|
53 | //@{
|
---|
54 |
|
---|
55 | HANDLE getCancelEventForCurrentThread();
|
---|
56 |
|
---|
57 | void* getNetworkDataForThread(CArchThread);
|
---|
58 |
|
---|
59 | static CArchMultithreadWindows* getInstance();
|
---|
60 |
|
---|
61 | //@}
|
---|
62 |
|
---|
63 | // IArchMultithread overrides
|
---|
64 | virtual CArchCond newCondVar();
|
---|
65 | virtual void closeCondVar(CArchCond);
|
---|
66 | virtual void signalCondVar(CArchCond);
|
---|
67 | virtual void broadcastCondVar(CArchCond);
|
---|
68 | virtual bool waitCondVar(CArchCond, CArchMutex, double timeout);
|
---|
69 | virtual CArchMutex newMutex();
|
---|
70 | virtual void closeMutex(CArchMutex);
|
---|
71 | virtual void lockMutex(CArchMutex);
|
---|
72 | virtual void unlockMutex(CArchMutex);
|
---|
73 | virtual CArchThread newThread(ThreadFunc, void*);
|
---|
74 | virtual CArchThread newCurrentThread();
|
---|
75 | virtual CArchThread copyThread(CArchThread);
|
---|
76 | virtual void closeThread(CArchThread);
|
---|
77 | virtual void cancelThread(CArchThread);
|
---|
78 | virtual void setPriorityOfThread(CArchThread, int n);
|
---|
79 | virtual void testCancelThread();
|
---|
80 | virtual bool wait(CArchThread, double timeout);
|
---|
81 | virtual bool isSameThread(CArchThread, CArchThread);
|
---|
82 | virtual bool isExitedThread(CArchThread);
|
---|
83 | virtual void* getResultOfThread(CArchThread);
|
---|
84 | virtual ThreadID getIDOfThread(CArchThread);
|
---|
85 | virtual void setSignalHandler(ESignal, SignalFunc, void*);
|
---|
86 | virtual void raiseSignal(ESignal);
|
---|
87 |
|
---|
88 | private:
|
---|
89 | CArchThreadImpl* find(DWORD id);
|
---|
90 | CArchThreadImpl* findNoRef(DWORD id);
|
---|
91 | CArchThreadImpl* findNoRefOrCreate(DWORD id);
|
---|
92 | void insert(CArchThreadImpl* thread);
|
---|
93 | void erase(CArchThreadImpl* thread);
|
---|
94 |
|
---|
95 | void refThread(CArchThreadImpl* rep);
|
---|
96 | void testCancelThreadImpl(CArchThreadImpl* rep);
|
---|
97 |
|
---|
98 | void doThreadFunc(CArchThread thread);
|
---|
99 | static unsigned int __stdcall threadFunc(void* vrep);
|
---|
100 |
|
---|
101 | private:
|
---|
102 | typedef std::list<CArchThread> CThreadList;
|
---|
103 |
|
---|
104 | static CArchMultithreadWindows* s_instance;
|
---|
105 |
|
---|
106 | CArchMutex m_threadMutex;
|
---|
107 |
|
---|
108 | CThreadList m_threadList;
|
---|
109 | CArchThread m_mainThread;
|
---|
110 |
|
---|
111 | SignalFunc m_signalFunc[kNUM_SIGNALS];
|
---|
112 | void* m_signalUserData[kNUM_SIGNALS];
|
---|
113 | };
|
---|
114 |
|
---|
115 | #endif
|
---|