source: trunk/synergy/lib/arch/CArchMultithreadPosix.h@ 3003

Last change on this file since 3003 was 2752, checked in by bird, 19 years ago

Two classes (CPMScreen and CPMKeyState) + the hook dll left (and debugging of course).

File size: 3.2 KB
Line 
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 CARCHMULTITHREADPOSIX_H
16#define CARCHMULTITHREADPOSIX_H
17
18#ifdef __OS2__
19
20#include "CArchMultithreadOS2.h"
21
22#else /* !__OS2__ */
23
24#include "IArchMultithread.h"
25#include "stdlist.h"
26#include <pthread.h>
27
28#define ARCH_MULTITHREAD CArchMultithreadPosix
29
30class CArchCondImpl {
31public:
32 pthread_cond_t m_cond;
33};
34
35class CArchMutexImpl {
36public:
37 pthread_mutex_t m_mutex;
38};
39
40//! Posix implementation of IArchMultithread
41class CArchMultithreadPosix : public IArchMultithread {
42public:
43 CArchMultithreadPosix();
44 virtual ~CArchMultithreadPosix();
45
46 //! @name manipulators
47 //@{
48
49 void setNetworkDataForCurrentThread(void*);
50
51 //@}
52 //! @name accessors
53 //@{
54
55 void* getNetworkDataForThread(CArchThread);
56
57 static CArchMultithreadPosix* getInstance();
58
59 //@}
60
61 // IArchMultithread overrides
62 virtual CArchCond newCondVar();
63 virtual void closeCondVar(CArchCond);
64 virtual void signalCondVar(CArchCond);
65 virtual void broadcastCondVar(CArchCond);
66 virtual bool waitCondVar(CArchCond, CArchMutex, double timeout);
67 virtual CArchMutex newMutex();
68 virtual void closeMutex(CArchMutex);
69 virtual void lockMutex(CArchMutex);
70 virtual void unlockMutex(CArchMutex);
71 virtual CArchThread newThread(ThreadFunc, void*);
72 virtual CArchThread newCurrentThread();
73 virtual CArchThread copyThread(CArchThread);
74 virtual void closeThread(CArchThread);
75 virtual void cancelThread(CArchThread);
76 virtual void setPriorityOfThread(CArchThread, int n);
77 virtual void testCancelThread();
78 virtual bool wait(CArchThread, double timeout);
79 virtual bool isSameThread(CArchThread, CArchThread);
80 virtual bool isExitedThread(CArchThread);
81 virtual void* getResultOfThread(CArchThread);
82 virtual ThreadID getIDOfThread(CArchThread);
83 virtual void setSignalHandler(ESignal, SignalFunc, void*);
84 virtual void raiseSignal(ESignal);
85
86private:
87 void startSignalHandler();
88
89 CArchThreadImpl* find(pthread_t thread);
90 CArchThreadImpl* findNoRef(pthread_t thread);
91 void insert(CArchThreadImpl* thread);
92 void erase(CArchThreadImpl* thread);
93
94 void refThread(CArchThreadImpl* rep);
95 void testCancelThreadImpl(CArchThreadImpl* rep);
96
97 void doThreadFunc(CArchThread thread);
98 static void* threadFunc(void* vrep);
99 static void threadCancel(int);
100 static void* threadSignalHandler(void* vrep);
101
102private:
103 typedef std::list<CArchThread> CThreadList;
104
105 static CArchMultithreadPosix* s_instance;
106
107 bool m_newThreadCalled;
108
109 CArchMutex m_threadMutex;
110 CArchThread m_mainThread;
111 CThreadList m_threadList;
112 ThreadID m_nextID;
113
114 pthread_t m_signalThread;
115 SignalFunc m_signalFunc[kNUM_SIGNALS];
116 void* m_signalUserData[kNUM_SIGNALS];
117};
118
119#endif /* !__OS2__ */
120#endif
Note: See TracBrowser for help on using the repository browser.