dvander@2726: /**
dvander@2726: * vim: set ts=4 :
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_SOURCEMOD_THREADWORKER_H
dvander@2726: #define _INCLUDE_SOURCEMOD_THREADWORKER_H
dvander@2726:
dvander@2726: #include "BaseWorker.h"
dvander@2726:
asherkin@3552: #define DEFAULT_THINK_TIME_MS 20
dvander@2726:
dvander@2726: class ThreadWorker : public BaseWorker, public IThread
dvander@2726: {
dvander@2726: public:
dvander@2726: ThreadWorker(IThreadWorkerCallbacks *hooks);
dvander@2726: ThreadWorker(IThreadWorkerCallbacks *hooks, IThreader *pThreader, unsigned int thinktime=DEFAULT_THINK_TIME_MS);
dvander@2726: virtual ~ThreadWorker();
dvander@2726: public: //IThread
dvander@2726: virtual void OnTerminate(IThreadHandle *pHandle, bool cancel);
dvander@2726: virtual void RunThread(IThreadHandle *pHandle);
dvander@2726: public: //IWorker
dvander@2726: //Controls the worker
dvander@2726: virtual bool Pause();
dvander@2726: virtual bool Unpause();
dvander@2726: virtual bool Start();
dvander@2726: virtual bool Stop(bool flush_cancel);
dvander@2726: //returns status and number of threads in queue
dvander@2726: virtual WorkerState GetStatus(unsigned int *numThreads);
asherkin@3704: //virtual void SetMaxThreadsPerFrame(unsigned int threads);
asherkin@3704: virtual void SetThinkTimePerFrame(unsigned int thinktime);
dvander@2726: public: //BaseWorker
dvander@2726: virtual void AddThreadToQueue(SWThreadHandle *pHandle);
dvander@2726: virtual SWThreadHandle *PopThreadFromQueue();
dvander@2726: protected:
dvander@2726: IThreader *m_Threader;
dvander@2726: IThreadHandle *me;
dvander@2726: unsigned int m_think_time;
dvander@4025: bool m_FlushType;
dvander@4025: ke::ConditionVariable monitor_;
dvander@2726: };
dvander@2726:
dvander@2726: #endif //_INCLUDE_SOURCEMOD_THREADWORKER_H