core/logic/thread/WinThreads.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed May 21 17:25:30 2014 -0400 (2014-05-21)
changeset 4377 7a44be5b7162
parent 4033 48eaea10c202
permissions -rw-r--r--
Trigger build for hl2sdk-l4d changes.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_WINTHREADS_H_
    33 #define _INCLUDE_WINTHREADS_H_
    34 
    35 #include <am-thread-utils.h>
    36 #include <am-utility.h>
    37 #include <windows.h>
    38 #include "IThreader.h"
    39 
    40 using namespace SourceMod;
    41 
    42 class WinThreader : public IThreader
    43 {
    44 public:
    45 	class ThreadHandle : public IThreadHandle, public ke::IRunnable
    46 	{
    47 		friend class WinThreader;
    48 		friend DWORD WINAPI Win32_ThreadGate(LPVOID param);
    49 	public:
    50 		ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params);
    51 		virtual ~ThreadHandle();
    52 	public:
    53 		virtual bool WaitForThread();
    54 		virtual void DestroyThis();
    55 		virtual IThreadCreator *Parent();
    56 		virtual void GetParams(ThreadParams *ptparams);
    57 		virtual ThreadPriority GetPriority();
    58 		virtual bool SetPriority(ThreadPriority prio);
    59 		virtual ThreadState GetState();
    60 		virtual bool Unpause();
    61 		virtual void Run();
    62 	protected:
    63 		IThreader *m_parent;		//Parent handle
    64 		ke::AutoPtr<ke::Thread> m_thread;
    65 		ThreadParams m_params;		//Current Parameters
    66 		IThread *m_run;				//Runnable context
    67 		ThreadState m_state;		//internal state
    68 		ke::ConditionVariable suspend_;
    69 	};
    70 
    71 public:
    72 	IMutex *MakeMutex();
    73 	void MakeThread(IThread *pThread);
    74 	IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags);
    75 	IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params);
    76 	void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min);
    77 	void ThreadSleep(unsigned int ms);
    78 	IEventSignal *MakeEventSignal();
    79 	IThreadWorker *MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded);
    80 	void DestroyWorker(IThreadWorker *pWorker);
    81 };
    82 
    83 #if defined SM_DEFAULT_THREADER && !defined SM_MAIN_THREADER
    84 #define SM_MAIN_THREADER WinThreader;
    85 typedef class WinThreader MainThreader;
    86 #endif
    87 
    88 #endif //_INCLUDE_WINTHREADS_H_