Updated some CS:GO gamedata.
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 #include "BaseWorker.h"
34 BaseWorker::BaseWorker(IThreadWorkerCallbacks *hooks) :
35 m_perFrame(SM_DEFAULT_THREADS_PER_FRAME),
36 m_state(Worker_Stopped),
41 BaseWorker::~BaseWorker()
43 if (m_state != Worker_Stopped || m_state != Worker_Invalid)
46 if (m_ThreadQueue.size())
50 void BaseWorker::MakeThread(IThread *pThread)
54 pt.flags = Thread_AutoRelease;
55 pt.prio = ThreadPrio_Normal;
57 MakeThread(pThread, &pt);
60 IThreadHandle *BaseWorker::MakeThread(IThread *pThread, ThreadFlags flags)
65 pt.prio = ThreadPrio_Normal;
67 return MakeThread(pThread, &pt);
70 IThreadHandle *BaseWorker::MakeThread(IThread *pThread, const ThreadParams *params)
72 if (m_state != Worker_Running)
75 SWThreadHandle *swt = new SWThreadHandle(this, params, pThread);
77 AddThreadToQueue(swt);
82 void BaseWorker::GetPriorityBounds(ThreadPriority &max, ThreadPriority &min)
84 max = ThreadPrio_Normal;
85 min = ThreadPrio_Normal;
88 unsigned int BaseWorker::Flush(bool flush_cancel)
93 while ((swt=PopThreadFromQueue()) != NULL)
95 swt->m_state = Thread_Done;
97 swt->pThread->RunThread(swt);
98 swt->pThread->OnTerminate(swt, flush_cancel);
99 if (swt->m_params.flags & Thread_AutoRelease)
107 SWThreadHandle *BaseWorker::PopThreadFromQueue()
109 if (!m_ThreadQueue.size())
112 SourceHook::List<SWThreadHandle *>::iterator begin;
115 begin = m_ThreadQueue.begin();
117 m_ThreadQueue.erase(begin);
122 void BaseWorker::AddThreadToQueue(SWThreadHandle *pHandle)
124 m_ThreadQueue.push_back(pHandle);
127 WorkerState BaseWorker::GetStatus(unsigned int *threads)
130 *threads = m_perFrame;
135 unsigned int BaseWorker::RunFrame()
137 unsigned int done = 0;
138 unsigned int max = m_perFrame;
139 SWThreadHandle *swt = NULL;
140 IThread *pThread = NULL;
144 if ((swt=PopThreadFromQueue()) == NULL)
148 pThread = swt->pThread;
149 swt->m_state = Thread_Running;
150 pThread->RunThread(swt);
151 swt->m_state = Thread_Done;
152 pThread->OnTerminate(swt, false);
153 if (swt->m_params.flags & Thread_AutoRelease)
163 void BaseWorker::SetMaxThreadsPerFrame(unsigned int threads)
165 m_perFrame = threads;
168 bool BaseWorker::Start()
170 if (m_state != Worker_Invalid && m_state != Worker_Stopped)
175 m_state = Worker_Running;
179 m_pHooks->OnWorkerStart(this);
185 bool BaseWorker::Stop(bool flush_cancel)
187 if (m_state == Worker_Invalid || m_state == Worker_Stopped)
192 if (m_state == Worker_Paused)
200 m_state = Worker_Stopped;
205 m_pHooks->OnWorkerStop(this);
211 bool BaseWorker::Pause()
213 if (m_state != Worker_Running)
218 m_state = Worker_Paused;
224 bool BaseWorker::Unpause()
226 if (m_state != Worker_Paused)
231 m_state = Worker_Running;
236 /***********************
237 * THREAD HANDLE STUFF *
238 ***********************/
240 void SWThreadHandle::DestroyThis()
245 void SWThreadHandle::GetParams(ThreadParams *p)
250 ThreadPriority SWThreadHandle::GetPriority()
252 return m_params.prio;
255 ThreadState SWThreadHandle::GetState()
260 IThreadCreator *SWThreadHandle::Parent()
265 bool SWThreadHandle::SetPriority(ThreadPriority prio)
267 if (m_params.prio != ThreadPrio_Normal)
270 m_params.prio = prio;
275 bool SWThreadHandle::Unpause()
277 if (m_state != Thread_Paused)
280 m_state = Thread_Running;
285 bool SWThreadHandle::WaitForThread()
290 SWThreadHandle::SWThreadHandle(IThreadCreator *parent, const ThreadParams *p, IThread *thread) :
291 m_state(Thread_Paused), m_params(*p), m_parent(parent), pThread(thread)
295 IThread *SWThreadHandle::GetThread()