dvander@2726: /**
dvander@4025: * vim: set ts=4 sw=4 tw=99 noet:
dvander@2726: * =============================================================================
dvander@2726: * SourceMod
dvander@2726: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
dvander@2726: * =============================================================================
dvander@2726: *
dvander@2726: * This program is free software; you can redistribute it and/or modify it under
dvander@2726: * the terms of the GNU General Public License, version 3.0, as published by the
dvander@2726: * Free Software Foundation.
dvander@2726: *
dvander@2726: * This program is distributed in the hope that it will be useful, but WITHOUT
dvander@2726: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@2726: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
dvander@2726: * details.
dvander@2726: *
dvander@2726: * You should have received a copy of the GNU General Public License along with
dvander@2726: * this program. If not, see .
dvander@2726: *
dvander@2726: * As a special exception, AlliedModders LLC gives you permission to link the
dvander@2726: * code of this program (as well as its derivative works) to "Half-Life 2," the
dvander@2726: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
dvander@2726: * by the Valve Corporation. You must obey the GNU General Public License in
dvander@2726: * all respects for all other code used. Additionally, AlliedModders LLC grants
dvander@2726: * this exception to all derivative works. AlliedModders LLC defines further
dvander@2726: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
dvander@2726: * or .
dvander@2726: *
dvander@2726: * Version: $Id$
dvander@2726: */
dvander@2726:
dvander@2726: #ifndef _INCLUDE_POSIXTHREADS_H_
dvander@2726: #define _INCLUDE_POSIXTHREADS_H_
dvander@2726:
dvander@2726: #include
dvander@4031: #include
dvander@2726: #include "IThreader.h"
dvander@2726:
dvander@2726: using namespace SourceMod;
dvander@2726:
dvander@2726: class PosixThreader : public IThreader
dvander@2726: {
dvander@2726: public:
dvander@4025: class ThreadHandle : public IThreadHandle, public ke::IRunnable
dvander@2726: {
dvander@2726: friend class PosixThreader;
dvander@2726: public:
dvander@2726: ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params);
dvander@2726: virtual ~ThreadHandle();
dvander@2726: public:
dvander@2726: virtual bool WaitForThread();
dvander@2726: virtual void DestroyThis();
dvander@2726: virtual IThreadCreator *Parent();
dvander@2726: virtual void GetParams(ThreadParams *ptparams);
dvander@2726: virtual ThreadPriority GetPriority();
dvander@2726: virtual bool SetPriority(ThreadPriority prio);
dvander@2726: virtual ThreadState GetState();
dvander@2726: virtual bool Unpause();
dvander@4025: public:
dvander@4025: void Run();
dvander@2726: protected:
dvander@2726: IThreader *m_parent; //Parent handle
dvander@2726: ThreadParams m_params; //Current Parameters
dvander@4025: IThread *m_run; //Runnable context
dvander@4025: ke::AutoPtr m_thread;
dvander@4025: ke::ConditionVariable m_runlock;
dvander@2726: ThreadState m_state; //internal state
dvander@2726: };
dvander@2726: public:
dvander@2726: IMutex *MakeMutex();
dvander@2726: void MakeThread(IThread *pThread);
dvander@2726: IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags);
dvander@2726: IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params);
dvander@2726: void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min);
dvander@2726: void ThreadSleep(unsigned int ms);
dvander@2726: IEventSignal *MakeEventSignal();
dvander@2726: IThreadWorker *MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded);
dvander@2726: void DestroyWorker(IThreadWorker *pWorker);
dvander@2726: };
dvander@2726:
dvander@2726: #if defined SM_DEFAULT_THREADER && !defined SM_MAIN_THREADER
dvander@2726: #define SM_MAIN_THREADER PosixThreader;
dvander@2726: typedef class PosixThreader MainThreader;
dvander@2726: #endif
dvander@2726:
dvander@2726: #endif //_INCLUDE_POSIXTHREADS_H_