Removed pointless "systems" folder from core.
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
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.
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
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/>.
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>.
32 #ifndef _INCLUDE_SOURCEMOD_BASEWORKER_H
33 #define _INCLUDE_SOURCEMOD_BASEWORKER_H
36 #include "ThreadSupport.h"
38 #define SM_DEFAULT_THREADS_PER_FRAME 1
43 class SWThreadHandle : public IThreadHandle
45 friend class BaseWorker;
47 SWThreadHandle(IThreadCreator *parent, const ThreadParams *p, IThread *thread);
50 //NOTE: We don't support this by default.
51 //It's specific usage that'd require many mutexes
52 virtual bool WaitForThread();
54 virtual void DestroyThis();
55 virtual IThreadCreator *Parent();
56 virtual void GetParams(ThreadParams *ptparams);
58 //Priorities not supported by default.
59 virtual ThreadPriority GetPriority();
60 virtual bool SetPriority(ThreadPriority prio);
62 virtual ThreadState GetState();
63 virtual bool Unpause();
66 ThreadParams m_params;
67 IThreadCreator *m_parent;
71 class BaseWorker : public IThreadWorker
74 BaseWorker(IThreadWorkerCallbacks *hooks);
75 virtual ~BaseWorker();
77 virtual unsigned int RunFrame();
80 virtual bool Unpause();
82 virtual bool Stop(bool flush_cancel);
83 //Flushes out any remaining threads
84 virtual unsigned int Flush(bool flush_cancel);
85 //returns status and number of threads in queue
86 virtual WorkerState GetStatus(unsigned int *numThreads);
87 public: //IThreadCreator
88 virtual void MakeThread(IThread *pThread);
89 virtual IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags);
90 virtual IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params);
91 virtual void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min);
93 virtual void AddThreadToQueue(SWThreadHandle *pHandle);
94 virtual SWThreadHandle *PopThreadFromQueue();
95 virtual void SetMaxThreadsPerFrame(unsigned int threads);
96 virtual unsigned int GetMaxThreadsPerFrame();
98 SourceHook::List<SWThreadHandle *> m_ThreadQueue;
99 unsigned int m_perFrame;
100 volatile WorkerState m_state;
101 IThreadWorkerCallbacks *m_pHooks;
104 #endif //_INCLUDE_SOURCEMOD_BASEWORKER_H