~nobuto/ubuntu/natty/synergy/merge-from-experimental

« back to all changes in this revision

Viewing changes to lib/arch/CArchMultithreadWindows.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Lutz
  • Date: 2003-10-31 19:36:30 UTC
  • Revision ID: james.westby@ubuntu.com-20031031193630-knbv79x5az7qh49y
Tags: upstream-1.0.14
ImportĀ upstreamĀ versionĀ 1.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        //
 
47
        // accessors
 
48
        //
 
49
 
 
50
        HANDLE                          getCancelEventForCurrentThread();
 
51
 
 
52
        static CArchMultithreadWindows* getInstance();
 
53
 
 
54
        // IArchMultithread overrides
 
55
        virtual CArchCond       newCondVar();
 
56
        virtual void            closeCondVar(CArchCond);
 
57
        virtual void            signalCondVar(CArchCond);
 
58
        virtual void            broadcastCondVar(CArchCond);
 
59
        virtual bool            waitCondVar(CArchCond, CArchMutex, double timeout);
 
60
        virtual CArchMutex      newMutex();
 
61
        virtual void            closeMutex(CArchMutex);
 
62
        virtual void            lockMutex(CArchMutex);
 
63
        virtual void            unlockMutex(CArchMutex);
 
64
        virtual CArchThread     newThread(ThreadFunc, void*);
 
65
        virtual CArchThread     newCurrentThread();
 
66
        virtual CArchThread     copyThread(CArchThread);
 
67
        virtual void            closeThread(CArchThread);
 
68
        virtual void            cancelThread(CArchThread);
 
69
        virtual void            setPriorityOfThread(CArchThread, int n);
 
70
        virtual void            testCancelThread();
 
71
        virtual bool            wait(CArchThread, double timeout);
 
72
        virtual EWaitResult     waitForEvent(CArchThread, double timeout);
 
73
        virtual bool            isSameThread(CArchThread, CArchThread);
 
74
        virtual bool            isExitedThread(CArchThread);
 
75
        virtual void*           getResultOfThread(CArchThread);
 
76
        virtual ThreadID        getIDOfThread(CArchThread);
 
77
 
 
78
private:
 
79
        CArchThreadImpl*        find(DWORD id);
 
80
        CArchThreadImpl*        findNoRef(DWORD id);
 
81
        CArchThreadImpl*        findNoRefOrCreate(DWORD id);
 
82
        void                            insert(CArchThreadImpl* thread);
 
83
        void                            erase(CArchThreadImpl* thread);
 
84
 
 
85
        void                            refThread(CArchThreadImpl* rep);
 
86
        void                            testCancelThreadImpl(CArchThreadImpl* rep);
 
87
 
 
88
        void                            doThreadFunc(CArchThread thread);
 
89
        static unsigned int __stdcall   threadFunc(void* vrep);
 
90
 
 
91
private:
 
92
        typedef std::list<CArchThread> CThreadList;
 
93
 
 
94
        static CArchMultithreadWindows* s_instance;
 
95
 
 
96
        CArchMutex                      m_threadMutex;
 
97
 
 
98
        CThreadList                     m_threadList;
 
99
};
 
100
 
 
101
#endif