3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #ifndef _INCLUDE_WINTHREADS_H_
16 #define _INCLUDE_WINTHREADS_H_
19 #include "IThreader.h"
21 using namespace SourceMod;
23 DWORD WINAPI Win32_ThreadGate(LPVOID param);
25 class WinThreader : public IThreader
28 class ThreadHandle : public IThreadHandle
30 friend class WinThreader;
31 friend DWORD WINAPI Win32_ThreadGate(LPVOID param);
33 ThreadHandle(IThreader *parent, HANDLE hthread, IThread *run, const ThreadParams *params);
34 virtual ~ThreadHandle();
36 virtual bool WaitForThread();
37 virtual void DestroyThis();
38 virtual IThreadCreator *Parent();
39 virtual void GetParams(ThreadParams *ptparams);
40 virtual ThreadPriority GetPriority();
41 virtual bool SetPriority(ThreadPriority prio);
42 virtual ThreadState GetState();
43 virtual bool Unpause();
45 IThreader *m_parent; //Parent handle
46 HANDLE m_thread; //Windows HANDLE
47 ThreadParams m_params; //Current Parameters
48 IThread *m_run; //Runnable context
49 ThreadState m_state; //internal state
50 CRITICAL_SECTION m_crit;
52 class WinMutex : public IMutex
55 WinMutex(HANDLE mutex) : m_mutex(mutex)
60 virtual bool TryLock();
62 virtual void Unlock();
63 virtual void DestroyThis();
67 class WinEvent : public IEventSignal
70 WinEvent(HANDLE event) : m_event(event)
76 virtual void Signal();
77 virtual void DestroyThis();
83 void MakeThread(IThread *pThread);
84 IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags);
85 IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params);
86 void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min);
87 void ThreadSleep(unsigned int ms);
88 IEventSignal *MakeEventSignal();
89 IThreadWorker *MakeWorker(bool threaded);
90 void DestroyWorker(IThreadWorker *pWorker);
93 #if defined SM_DEFAULT_THREADER && !defined SM_MAIN_THREADER
94 #define SM_MAIN_THREADER WinThreader;
95 typedef class WinThreader MainThreader;
98 #endif //_INCLUDE_WINTHREADS_H_