Trigger build for hl2sdk-l4d changes.
2 * vim: set ts=4 sw=4 tw=99 noet:
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>.
33 #include "PosixThreads.h"
34 #include "ThreadWorker.h"
36 IThreadWorker *PosixThreader::MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded)
40 return new ThreadWorker(hooks, this, DEFAULT_THINK_TIME_MS);
42 return new BaseWorker(hooks);
46 void PosixThreader::DestroyWorker(IThreadWorker *pWorker)
51 void PosixThreader::ThreadSleep(unsigned int ms)
56 void PosixThreader::GetPriorityBounds(ThreadPriority &max, ThreadPriority &min)
58 max = ThreadPrio_Normal;
59 min = ThreadPrio_Normal;
62 IMutex *PosixThreader::MakeMutex()
64 return new CompatMutex();
67 void PosixThreader::MakeThread(IThread *pThread)
69 ThreadParams defparams;
71 defparams.flags = Thread_AutoRelease;
72 defparams.prio = ThreadPrio_Normal;
74 MakeThread(pThread, &defparams);
77 IThreadHandle *PosixThreader::MakeThread(IThread *pThread, ThreadFlags flags)
79 ThreadParams defparams;
81 defparams.flags = flags;
82 defparams.prio = ThreadPrio_Normal;
84 return MakeThread(pThread, &defparams);
87 void PosixThreader::ThreadHandle::Run()
89 // Wait for an unpause if necessary.
91 ke::AutoLock lock(&m_runlock);
92 if (m_state == Thread_Paused)
96 m_run->RunThread(this);
97 m_state = Thread_Done;
98 m_run->OnTerminate(this, false);
100 if (m_params.flags & Thread_AutoRelease)
104 ThreadParams g_defparams;
105 IThreadHandle *PosixThreader::MakeThread(IThread *pThread, const ThreadParams *params)
108 params = &g_defparams;
110 ke::AutoPtr<ThreadHandle> pHandle(new ThreadHandle(this, pThread, params));
112 pHandle->m_thread = new ke::Thread(pHandle, "SourceMod");
113 if (!pHandle->m_thread->Succeeded())
116 if (!(params->flags & Thread_CreateSuspended))
119 return pHandle.take();
122 IEventSignal *PosixThreader::MakeEventSignal()
124 return new CompatCondVar();
131 PosixThreader::ThreadHandle::ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params) :
132 m_parent(parent), m_params(*params), m_run(run), m_state(Thread_Paused)
136 PosixThreader::ThreadHandle::~ThreadHandle()
140 bool PosixThreader::ThreadHandle::WaitForThread()
149 ThreadState PosixThreader::ThreadHandle::GetState()
154 IThreadCreator *PosixThreader::ThreadHandle::Parent()
159 void PosixThreader::ThreadHandle::DestroyThis()
161 if (m_params.flags & Thread_AutoRelease)
167 void PosixThreader::ThreadHandle::GetParams(ThreadParams *ptparams)
172 *ptparams = m_params;
175 ThreadPriority PosixThreader::ThreadHandle::GetPriority()
177 return ThreadPrio_Normal;
180 bool PosixThreader::ThreadHandle::SetPriority(ThreadPriority prio)
182 return (prio == ThreadPrio_Normal);
185 bool PosixThreader::ThreadHandle::Unpause()
187 if (m_state != Thread_Paused)
190 ke::AutoLock lock(&m_runlock);
191 m_state = Thread_Running;