00001 /* 00002 * synergy -- mouse and keyboard sharing utility 00003 * Copyright (C) 2012 Bolton Software Ltd. 00004 * Copyright (C) 2002 Chris Schoeneman 00005 * 00006 * This package is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * found in the file COPYING that should have accompanied this file. 00009 * 00010 * This package is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #ifndef CARCHMULTITHREADPOSIX_H 00020 #define CARCHMULTITHREADPOSIX_H 00021 00022 #include "IArchMultithread.h" 00023 #include "stdlist.h" 00024 #include <pthread.h> 00025 00026 #define ARCH_MULTITHREAD CArchMultithreadPosix 00027 00028 class CArchCondImpl { 00029 public: 00030 pthread_cond_t m_cond; 00031 }; 00032 00033 class CArchMutexImpl { 00034 public: 00035 pthread_mutex_t m_mutex; 00036 }; 00037 00039 class CArchMultithreadPosix : public IArchMultithread { 00040 public: 00041 CArchMultithreadPosix(); 00042 virtual ~CArchMultithreadPosix(); 00043 00045 00046 00047 void setNetworkDataForCurrentThread(void*); 00048 00050 00051 00052 00053 void* getNetworkDataForThread(CArchThread); 00054 00055 static CArchMultithreadPosix* getInstance(); 00056 00058 00059 // IArchMultithread overrides 00060 virtual CArchCond newCondVar(); 00061 virtual void closeCondVar(CArchCond); 00062 virtual void signalCondVar(CArchCond); 00063 virtual void broadcastCondVar(CArchCond); 00064 virtual bool waitCondVar(CArchCond, CArchMutex, double timeout); 00065 virtual CArchMutex newMutex(); 00066 virtual void closeMutex(CArchMutex); 00067 virtual void lockMutex(CArchMutex); 00068 virtual void unlockMutex(CArchMutex); 00069 virtual CArchThread newThread(ThreadFunc, void*); 00070 virtual CArchThread newCurrentThread(); 00071 virtual CArchThread copyThread(CArchThread); 00072 virtual void closeThread(CArchThread); 00073 virtual void cancelThread(CArchThread); 00074 virtual void setPriorityOfThread(CArchThread, int n); 00075 virtual void testCancelThread(); 00076 virtual bool wait(CArchThread, double timeout); 00077 virtual bool isSameThread(CArchThread, CArchThread); 00078 virtual bool isExitedThread(CArchThread); 00079 virtual void* getResultOfThread(CArchThread); 00080 virtual ThreadID getIDOfThread(CArchThread); 00081 virtual void setSignalHandler(ESignal, SignalFunc, void*); 00082 virtual void raiseSignal(ESignal); 00083 00084 private: 00085 void startSignalHandler(); 00086 00087 CArchThreadImpl* find(pthread_t thread); 00088 CArchThreadImpl* findNoRef(pthread_t thread); 00089 void insert(CArchThreadImpl* thread); 00090 void erase(CArchThreadImpl* thread); 00091 00092 void refThread(CArchThreadImpl* rep); 00093 void testCancelThreadImpl(CArchThreadImpl* rep); 00094 00095 void doThreadFunc(CArchThread thread); 00096 static void* threadFunc(void* vrep); 00097 static void threadCancel(int); 00098 static void* threadSignalHandler(void* vrep); 00099 00100 private: 00101 typedef std::list<CArchThread> CThreadList; 00102 00103 static CArchMultithreadPosix* s_instance; 00104 00105 bool m_newThreadCalled; 00106 00107 CArchMutex m_threadMutex; 00108 CArchThread m_mainThread; 00109 CThreadList m_threadList; 00110 ThreadID m_nextID; 00111 00112 pthread_t m_signalThread; 00113 SignalFunc m_signalFunc[kNUM_SIGNALS]; 00114 void* m_signalUserData[kNUM_SIGNALS]; 00115 }; 00116 00117 #endif
1.7.1