2003-01-04 22:01:32 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CARCHMULTITHREADWINDOWS_H
|
|
|
|
#define CARCHMULTITHREADWINDOWS_H
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
|
|
|
#include "IArchMultithread.h"
|
|
|
|
#include "stdlist.h"
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#define ARCH_MULTITHREAD CArchMultithreadWindows
|
|
|
|
|
|
|
|
class CArchCondImpl {
|
|
|
|
public:
|
|
|
|
enum { kSignal = 0, kBroadcast };
|
|
|
|
|
|
|
|
HANDLE m_events[2];
|
|
|
|
mutable int m_waitCount;
|
|
|
|
CArchMutex m_waitCountMutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CArchMutexImpl {
|
|
|
|
public:
|
|
|
|
CRITICAL_SECTION m_mutex;
|
|
|
|
};
|
|
|
|
|
2003-01-05 21:48:54 +00:00
|
|
|
//! Win32 implementation of IArchMultithread
|
2003-01-04 22:01:32 +00:00
|
|
|
class CArchMultithreadWindows : public IArchMultithread {
|
|
|
|
public:
|
|
|
|
CArchMultithreadWindows();
|
|
|
|
virtual ~CArchMultithreadWindows();
|
|
|
|
|
2004-02-28 12:19:49 +00:00
|
|
|
//
|
|
|
|
// manipulators
|
|
|
|
//
|
|
|
|
|
|
|
|
void setNetworkDataForCurrentThread(void*);
|
|
|
|
|
2003-01-04 22:01:32 +00:00
|
|
|
//
|
|
|
|
// accessors
|
|
|
|
//
|
|
|
|
|
|
|
|
HANDLE getCancelEventForCurrentThread();
|
|
|
|
|
2004-02-28 12:19:49 +00:00
|
|
|
void* getNetworkDataForThread(CArchThread);
|
|
|
|
|
2003-01-04 22:01:32 +00:00
|
|
|
static CArchMultithreadWindows* getInstance();
|
|
|
|
|
|
|
|
// IArchMultithread overrides
|
|
|
|
virtual CArchCond newCondVar();
|
|
|
|
virtual void closeCondVar(CArchCond);
|
|
|
|
virtual void signalCondVar(CArchCond);
|
|
|
|
virtual void broadcastCondVar(CArchCond);
|
|
|
|
virtual bool waitCondVar(CArchCond, CArchMutex, double timeout);
|
|
|
|
virtual CArchMutex newMutex();
|
|
|
|
virtual void closeMutex(CArchMutex);
|
|
|
|
virtual void lockMutex(CArchMutex);
|
|
|
|
virtual void unlockMutex(CArchMutex);
|
|
|
|
virtual CArchThread newThread(ThreadFunc, void*);
|
|
|
|
virtual CArchThread newCurrentThread();
|
|
|
|
virtual CArchThread copyThread(CArchThread);
|
|
|
|
virtual void closeThread(CArchThread);
|
|
|
|
virtual void cancelThread(CArchThread);
|
|
|
|
virtual void setPriorityOfThread(CArchThread, int n);
|
|
|
|
virtual void testCancelThread();
|
|
|
|
virtual bool wait(CArchThread, double timeout);
|
|
|
|
virtual bool isSameThread(CArchThread, CArchThread);
|
|
|
|
virtual bool isExitedThread(CArchThread);
|
|
|
|
virtual void* getResultOfThread(CArchThread);
|
|
|
|
virtual ThreadID getIDOfThread(CArchThread);
|
2004-02-28 17:49:29 +00:00
|
|
|
virtual void setSignalHandler(ESignal, SignalFunc, void*);
|
|
|
|
virtual void raiseSignal(ESignal);
|
2003-01-04 22:01:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
CArchThreadImpl* find(DWORD id);
|
|
|
|
CArchThreadImpl* findNoRef(DWORD id);
|
2003-01-22 08:36:43 +00:00
|
|
|
CArchThreadImpl* findNoRefOrCreate(DWORD id);
|
2003-01-04 22:01:32 +00:00
|
|
|
void insert(CArchThreadImpl* thread);
|
|
|
|
void erase(CArchThreadImpl* thread);
|
|
|
|
|
|
|
|
void refThread(CArchThreadImpl* rep);
|
|
|
|
void testCancelThreadImpl(CArchThreadImpl* rep);
|
|
|
|
|
|
|
|
void doThreadFunc(CArchThread thread);
|
|
|
|
static unsigned int __stdcall threadFunc(void* vrep);
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::list<CArchThread> CThreadList;
|
|
|
|
|
|
|
|
static CArchMultithreadWindows* s_instance;
|
|
|
|
|
|
|
|
CArchMutex m_threadMutex;
|
|
|
|
|
|
|
|
CThreadList m_threadList;
|
2004-02-28 12:19:49 +00:00
|
|
|
CArchThread m_mainThread;
|
|
|
|
|
2004-02-28 17:49:29 +00:00
|
|
|
SignalFunc m_signalFunc[kNUM_SIGNALS];
|
|
|
|
void* m_signalUserData[kNUM_SIGNALS];
|
2003-01-04 22:01:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|