From 4819864a5ea6672c0c212adebd7d7888cbf52517 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 9 Jul 2007 02:44:20 +0000 Subject: [PATCH] removed threader -- it is achieving the holy status of being promoted to Core --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401085 --- extensions/threader/Makefile | 91 ------ extensions/threader/extension.cpp | 42 --- extensions/threader/extension.h | 110 ------- extensions/threader/msvc8/threader.sln | 20 -- extensions/threader/msvc8/threader.vcproj | 290 ----------------- extensions/threader/sdk/smsdk_config.h | 49 --- extensions/threader/sdk/smsdk_ext.cpp | 334 -------------------- extensions/threader/sdk/smsdk_ext.h | 213 ------------- extensions/threader/svn_version.h | 12 - extensions/threader/svn_version.tpl | 12 - extensions/threader/thread/BaseWorker.cpp | 272 ---------------- extensions/threader/thread/BaseWorker.h | 95 ------ extensions/threader/thread/PosixThreads.cpp | 301 ------------------ extensions/threader/thread/PosixThreads.h | 107 ------- extensions/threader/thread/ThreadSupport.h | 33 -- extensions/threader/thread/ThreadWorker.cpp | 281 ---------------- extensions/threader/thread/ThreadWorker.h | 63 ---- extensions/threader/thread/WinThreads.cpp | 327 ------------------- extensions/threader/thread/WinThreads.h | 107 ------- extensions/threader/version.rc | 104 ------ 20 files changed, 2863 deletions(-) delete mode 100644 extensions/threader/Makefile delete mode 100644 extensions/threader/extension.cpp delete mode 100644 extensions/threader/extension.h delete mode 100644 extensions/threader/msvc8/threader.sln delete mode 100644 extensions/threader/msvc8/threader.vcproj delete mode 100644 extensions/threader/sdk/smsdk_config.h delete mode 100644 extensions/threader/sdk/smsdk_ext.cpp delete mode 100644 extensions/threader/sdk/smsdk_ext.h delete mode 100644 extensions/threader/svn_version.h delete mode 100644 extensions/threader/svn_version.tpl delete mode 100644 extensions/threader/thread/BaseWorker.cpp delete mode 100644 extensions/threader/thread/BaseWorker.h delete mode 100644 extensions/threader/thread/PosixThreads.cpp delete mode 100644 extensions/threader/thread/PosixThreads.h delete mode 100644 extensions/threader/thread/ThreadSupport.h delete mode 100644 extensions/threader/thread/ThreadWorker.cpp delete mode 100644 extensions/threader/thread/ThreadWorker.h delete mode 100644 extensions/threader/thread/WinThreads.cpp delete mode 100644 extensions/threader/thread/WinThreads.h delete mode 100644 extensions/threader/version.rc diff --git a/extensions/threader/Makefile b/extensions/threader/Makefile deleted file mode 100644 index af1b4dc2..00000000 --- a/extensions/threader/Makefile +++ /dev/null @@ -1,91 +0,0 @@ -#(C)2004-2006 SourceMM Development Team -# Makefile written by David "BAILOPAN" Anderson - -SMSDK = ../.. -SRCDS = ~/srcds -SOURCEMM = ../../../../sourcemm - -##################################### -### EDIT BELOW FOR OTHER PROJECTS ### -##################################### - -PROJECT = threader - -#Uncomment for SourceMM-enabled extensions -#LINK_HL2 = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so - -OBJECTS = sdk/smsdk_ext.cpp extension.cpp thread/BaseWorker.cpp thread/PosixThreads.cpp \ - thread/ThreadWorker.cpp - -############################################## -### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ### -############################################## - -C_OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing -C_DEBUG_FLAGS = -g -ggdb3 -CPP_GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden -CPP = gcc-4.1 - -HL2PUB = $(HL2SDK)/public -HL2LIB = $(HL2SDK)/linux_sdk -HL2SDK = $(SOURCEMM)/hl2sdk -SMM_TRUNK = $(SOURCEMM)/trunk - -LINK = $(LINK_HL2) -lpthread -static-libgcc - -INCLUDE = -I. -I.. -Isdk -Ithread -I$(HL2PUB) -I$(HL2PUB)/dlls -I$(HL2PUB)/engine -I$(HL2PUB)/tier0 -I$(HL2PUB)/tier1 \ - -I$(HL2PUB)/vstdlib -I$(HL2SDK)/tier1 -I$(SMM_TRUNK) -I$(SMM_TRUNK)/sourcehook -I$(SMM_TRUNK)/sourcemm \ - -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn -I$(SMSDK)/public/extensions \ - -CFLAGS = -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -Werror -fPIC -msse -DSOURCEMOD_BUILD -DSM_DEFAULT_THREADER -CPPFLAGS = -Wno-non-virtual-dtor -fno-exceptions -fno-rtti - -################################################ -### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ### -################################################ - -ifeq "$(DEBUG)" "true" - BIN_DIR = Debug - CFLAGS += $(C_DEBUG_FLAGS) -else - BIN_DIR = Release - CFLAGS += $(C_OPT_FLAGS) -endif - - -GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1) -ifeq "$(GCC_VERSION)" "4" - CPPFLAGS += $(CPP_GCC4_FLAGS) -endif - -BINARY = $(PROJECT).ext.so - -OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) - -$(BIN_DIR)/%.o: %.cpp - $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< - -all: - mkdir -p $(BIN_DIR)/sdk - mkdir -p $(BIN_DIR)/thread - ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so - ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so - $(MAKE) extension - -extension: $(OBJ_LINUX) - $(CPP) $(INCLUDE) $(CFLAGS) $(CPPFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) - -debug: - $(MAKE) all DEBUG=true - -default: all - -clean: - rm -rf Release/*.o - rm -rf Release/sdk/*.o - rm -rf Release/thread/*.o - rm -rf Release/$(BINARY) - rm -rf Debug/*.o - rm -rf Debug/sdk/*.o - rm -rf Debug/thread/*.o - rm -rf Debug/$(BINARY) \ No newline at end of file diff --git a/extensions/threader/extension.cpp b/extensions/threader/extension.cpp deleted file mode 100644 index 5ddbb20b..00000000 --- a/extensions/threader/extension.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threading Extension - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#include "extension.h" -#include "thread/ThreadSupport.h" - -/** - * @file extension.cpp - * @brief Implements threader extension code. - */ - -Sample g_Sample; -MainThreader g_Threader; - -SMEXT_LINK(&g_Sample); - -bool Sample::SDK_OnLoad(char *error, size_t maxlength, bool late) -{ - g_pShareSys->AddInterface(myself, &g_Threader); - - return true; -} diff --git a/extensions/threader/extension.h b/extensions/threader/extension.h deleted file mode 100644 index 450a4369..00000000 --- a/extensions/threader/extension.h +++ /dev/null @@ -1,110 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threading Extension - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ -#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ - -/** - * @file extension.h - * @brief Threader extension code header. - */ - -#include "smsdk_ext.h" - -/** - * @brief Implementation of the threader extension. - * Note: Uncomment one of the pre-defined virtual functions in order to use it. - */ -class Sample : public SDKExtension -{ -public: - /** - * @brief This is called after the initial loading sequence has been processed. - * - * @param error Error message buffer. - * @param maxlength Size of error message buffer. - * @param late Whether or not the module was loaded after map load. - * @return True to succeed loading, false to fail. - */ - virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); - - /** - * @brief This is called right before the extension is unloaded. - */ - //virtual void SDK_OnUnload(); - - /** - * @brief This is called once all known extensions have been loaded. - * Note: It is is a good idea to add natives here, if any are provided. - */ - //virtual void SDK_OnAllLoaded(); - - /** - * @brief Called when the pause state is changed. - */ - //virtual void SDK_OnPauseChange(bool paused); - - /** - * @brief this is called when Core wants to know if your extension is working. - * - * @param error Error message buffer. - * @param maxlength Size of error message buffer. - * @return True if working, false otherwise. - */ - //virtual bool QueryRunning(char *error, size_t maxlength); -public: -#if defined SMEXT_CONF_METAMOD - /** - * @brief Called when Metamod is attached, before the extension version is called. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @param late Whether or not Metamod considers this a late load. - * @return True to succeed, false to fail. - */ - //virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); - - /** - * @brief Called when Metamod is detaching, after the extension version is called. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - //virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); - - /** - * @brief Called when Metamod's pause state is changing. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param paused Pause state being set. - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - //virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); -#endif -}; - -#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ diff --git a/extensions/threader/msvc8/threader.sln b/extensions/threader/msvc8/threader.sln deleted file mode 100644 index c2d90607..00000000 --- a/extensions/threader/msvc8/threader.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "threader", "threader.vcproj", "{C9F9E996-0C20-4D96-8E52-4530F41E22CE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C9F9E996-0C20-4D96-8E52-4530F41E22CE}.Debug|Win32.ActiveCfg = Debug|Win32 - {C9F9E996-0C20-4D96-8E52-4530F41E22CE}.Debug|Win32.Build.0 = Debug|Win32 - {C9F9E996-0C20-4D96-8E52-4530F41E22CE}.Release|Win32.ActiveCfg = Release|Win32 - {C9F9E996-0C20-4D96-8E52-4530F41E22CE}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/extensions/threader/msvc8/threader.vcproj b/extensions/threader/msvc8/threader.vcproj deleted file mode 100644 index 7d91c6ba..00000000 --- a/extensions/threader/msvc8/threader.vcproj +++ /dev/null @@ -1,290 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/extensions/threader/sdk/smsdk_config.h b/extensions/threader/sdk/smsdk_config.h deleted file mode 100644 index 1c743e7f..00000000 --- a/extensions/threader/sdk/smsdk_config.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. - * All rights reserved. - * =============================================================== - * - * This file is part of the SourceMod/SourcePawn SDK. This file may only be - * used or modified under the Terms and Conditions of its License Agreement, - * which is found in public/licenses/LICENSE.txt. As of this notice, derivative - * works must be licensed under the GNU General Public License (version 2 or - * greater). A copy of the GPL is included under public/licenses/GPL.txt. - * - * To view the latest information, see: http://www.sourcemod.net/license.php - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ -#define _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ -#include "svn_version.h" - -/** - * @file smsdk_config.h - * @brief Contains macros for configuring basic extension information. - */ - -/* Basic information exposed publicly */ -#define SMEXT_CONF_NAME "Threader" -#define SMEXT_CONF_DESCRIPTION "Provides threading to other modules" -#define SMEXT_CONF_VERSION SVN_FULL_VERSION -#define SMEXT_CONF_AUTHOR "AlliedModders" -#define SMEXT_CONF_URL "http://www.sourcemod.net/" -#define SMEXT_CONF_LOGTAG "THREADER" -#define SMEXT_CONF_LICENSE "GPL" -#define SMEXT_CONF_DATESTRING __DATE__ - -/** - * @brief Exposes plugin's main interface. - */ -#define SMEXT_LINK(name) SDKExtension *g_pExtensionIface = name; - -/** - * @brief Sets whether or not this plugin required Metamod. - * NOTE: Uncomment to enable, comment to disable. - */ -//#define SMEXT_CONF_METAMOD - -#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ diff --git a/extensions/threader/sdk/smsdk_ext.cpp b/extensions/threader/sdk/smsdk_ext.cpp deleted file mode 100644 index d7d3ba02..00000000 --- a/extensions/threader/sdk/smsdk_ext.cpp +++ /dev/null @@ -1,334 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. - * All rights reserved. - * =============================================================== - * - * This file is part of the SourceMod/SourcePawn SDK. This file may only be - * used or modified under the Terms and Conditions of its License Agreement, - * which is found in public/licenses/LICENSE.txt. As of this notice, derivative - * works must be licensed under the GNU General Public License (version 2 or - * greater). A copy of the GPL is included under public/licenses/GPL.txt. - * - * To view the latest information, see: http://www.sourcemod.net/license.php - * - * Version: $Id$ - */ - -#include -#include -#include "smsdk_ext.h" - -/** - * @file smsdk_ext.cpp - * @brief Contains wrappers for making Extensions easier to write. - */ - -IShareSys *g_pShareSys = NULL; /**< Share system */ -IExtension *myself = NULL; /**< Ourself */ -IHandleSys *g_pHandleSys = NULL; /**< Handle system */ -ISourceMod *g_pSM = NULL; /**< SourceMod helpers */ -IForwardManager *g_pForwards = NULL; /**< Forward system */ - -/** Exports the main interface */ -PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() -{ - return g_pExtensionIface; -} - -SDKExtension::SDKExtension() -{ -#if defined SMEXT_CONF_METAMOD - m_SourceMMLoaded = false; - m_WeAreUnloaded = false; - m_WeGotPauseChange = false; -#endif -} - -bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late) -{ - g_pShareSys = sys; - myself = me; - -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; - - if (!m_SourceMMLoaded) - { - if (error) - { - snprintf(error, maxlength, "Metamod attach failed"); - } - return false; - } -#endif - - SM_GET_IFACE(HANDLESYSTEM, g_pHandleSys); - SM_GET_IFACE(SOURCEMOD, g_pSM); - SM_GET_IFACE(FORWARDMANAGER, g_pForwards); - - if (SDK_OnLoad(error, maxlength, late)) - { -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; -#endif - return true; - } - - return false; -} - -bool SDKExtension::IsMetamodExtension() -{ -#if defined SMEXT_CONF_METAMOD - return true; -#else - return false; -#endif -} - -void SDKExtension::OnExtensionPauseChange(bool state) -{ -#if defined SMEXT_CONF_METAMOD - m_WeGotPauseChange = true; -#endif - SDK_OnPauseChange(state); -} - -void SDKExtension::OnExtensionsAllLoaded() -{ - SDK_OnAllLoaded(); -} - -void SDKExtension::OnExtensionUnload() -{ -#if defined SMEXT_CONF_METAMOD - m_WeAreUnloaded = true; -#endif - SDK_OnUnload(); -} - -const char *SDKExtension::GetExtensionAuthor() -{ - return SMEXT_CONF_AUTHOR; -} - -const char *SDKExtension::GetExtensionDateString() -{ - return SMEXT_CONF_DATESTRING; -} - -const char *SDKExtension::GetExtensionDescription() -{ - return SMEXT_CONF_DESCRIPTION; -} - -const char *SDKExtension::GetExtensionVerString() -{ - return SMEXT_CONF_VERSION; -} - -const char *SDKExtension::GetExtensionName() -{ - return SMEXT_CONF_NAME; -} - -const char *SDKExtension::GetExtensionTag() -{ - return SMEXT_CONF_LOGTAG; -} - -const char *SDKExtension::GetExtensionURL() -{ - return SMEXT_CONF_URL; -} - -bool SDKExtension::SDK_OnLoad(char *error, size_t maxlength, bool late) -{ - return true; -} - -void SDKExtension::SDK_OnUnload() -{ -} - -void SDKExtension::SDK_OnPauseChange(bool paused) -{ -} - -void SDKExtension::SDK_OnAllLoaded() -{ -} - -#if defined SMEXT_CONF_METAMOD - -PluginId g_PLID = 0; /**< Metamod plugin ID */ -ISmmPlugin *g_PLAPI = NULL; /**< Metamod plugin API */ -SourceHook::ISourceHook *g_SHPtr = NULL; /**< SourceHook pointer */ -ISmmAPI *g_SMAPI = NULL; /**< SourceMM API pointer */ - -IVEngineServer *engine = NULL; /**< IVEngineServer pointer */ -IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ - -/** Exposes the extension to Metamod */ -SMM_API void *PL_EXPOSURE(const char *name, int *code) -{ - if (name && !strcmp(name, PLAPI_NAME)) - { - if (code) - { - *code = IFACE_OK; - } - return static_cast(g_pExtensionIface); - } - - if (code) - { - *code = IFACE_FAILED; - } - - return NULL; -} - -bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) -{ - PLUGIN_SAVEVARS(); - - GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); - GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); - - m_SourceMMLoaded = true; - - return SDK_OnMetamodLoad(ismm, error, maxlen, late); -} - -bool SDKExtension::Unload(char *error, size_t maxlen) -{ - if (!m_WeAreUnloaded) - { - if (error) - { - snprintf(error, maxlen, "This extension must be unloaded by SourceMod."); - } - return false; - } - - return SDK_OnMetamodUnload(error, maxlen); -} - -bool SDKExtension::Pause(char *error, size_t maxlen) -{ - if (!m_WeGotPauseChange) - { - if (error) - { - snprintf(error, maxlen, "This extension must be paused by SourceMod."); - } - return false; - } - - m_WeGotPauseChange = false; - - return SDK_OnMetamodPauseChange(true, error, maxlen); -} - -bool SDKExtension::Unpause(char *error, size_t maxlen) -{ - if (!m_WeGotPauseChange) - { - if (error) - { - snprintf(error, maxlen, "This extension must be unpaused by SourceMod."); - } - return false; - } - - m_WeGotPauseChange = false; - - return SDK_OnMetamodPauseChange(false, error, maxlen); -} - -const char *SDKExtension::GetAuthor() -{ - return GetExtensionAuthor(); -} - -const char *SDKExtension::GetDate() -{ - return GetExtensionDateString(); -} - -const char *SDKExtension::GetDescription() -{ - return GetExtensionDescription(); -} - -const char *SDKExtension::GetLicense() -{ - return SMEXT_CONF_LICENSE; -} - -const char *SDKExtension::GetLogTag() -{ - return GetExtensionTag(); -} - -const char *SDKExtension::GetName() -{ - return GetExtensionName(); -} - -const char *SDKExtension::GetURL() -{ - return GetExtensionURL(); -} - -const char *SDKExtension::GetVersion() -{ - return GetExtensionVerString(); -} - -bool SDKExtension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late) -{ - return true; -} - -bool SDKExtension::SDK_OnMetamodUnload(char *error, size_t maxlength) -{ - return true; -} - -bool SDKExtension::SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength) -{ - return true; -} - -#endif - -/* Overload a few things to prevent libstdc++ linking */ -#if defined __linux__ -extern "C" void __cxa_pure_virtual(void) -{ -} - -void *operator new(size_t size) -{ - return malloc(size); -} - -void *operator new[](size_t size) -{ - return malloc(size); -} - -void operator delete(void *ptr) -{ - free(ptr); -} - -void operator delete[](void * ptr) -{ - free(ptr); -} -#endif diff --git a/extensions/threader/sdk/smsdk_ext.h b/extensions/threader/sdk/smsdk_ext.h deleted file mode 100644 index 808e9759..00000000 --- a/extensions/threader/sdk/smsdk_ext.h +++ /dev/null @@ -1,213 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. - * All rights reserved. - * =============================================================== - * - * This file is part of the SourceMod/SourcePawn SDK. This file may only be - * used or modified under the Terms and Conditions of its License Agreement, - * which is found in public/licenses/LICENSE.txt. As of this notice, derivative - * works must be licensed under the GNU General Public License (version 2 or - * greater). A copy of the GPL is included under public/licenses/GPL.txt. - * - * To view the latest information, see: http://www.sourcemod.net/license.php - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ -#define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ - -/** - * @file smsdk_ext.h - * @brief Contains wrappers for making Extensions easier to write. - */ - -#include "smsdk_config.h" -#include -#include -#include -#include -#include -#include - -#if defined SMEXT_CONF_METAMOD -#include -#include -#endif - -using namespace SourceMod; -using namespace SourcePawn; - -class SDKExtension : -#if defined SMEXT_CONF_METAMOD - public ISmmPlugin, -#endif - public IExtensionInterface -{ -public: - /** Constructor */ - SDKExtension(); -public: - /** - * @brief This is called after the initial loading sequence has been processed. - * - * @param error Error message buffer. - * @param maxlength Size of error message buffer. - * @param late Whether or not the module was loaded after map load. - * @return True to succeed loading, false to fail. - */ - virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); - - /** - * @brief This is called right before the extension is unloaded. - */ - virtual void SDK_OnUnload(); - - /** - * @brief This is called once all known extensions have been loaded. - */ - virtual void SDK_OnAllLoaded(); - - /** - * @brief Called when the pause state is changed. - */ - virtual void SDK_OnPauseChange(bool paused); - -#if defined SMEXT_CONF_METAMOD - /** - * @brief Called when Metamod is attached, before the extension version is called. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @param late Whether or not Metamod considers this a late load. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); - - /** - * @brief Called when Metamod is detaching, after the extension version is called. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); - - /** - * @brief Called when Metamod's pause state is changing. - * NOTE: By default this is blocked unless sent from SourceMod. - * - * @param paused Pause state being set. - * @param error Error buffer. - * @param maxlength Maximum size of error buffer. - * @return True to succeed, false to fail. - */ - virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); -#endif - -public: // IExtensionInterface - virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late); - virtual void OnExtensionUnload(); - virtual void OnExtensionsAllLoaded(); - - /** Returns whether or not this is a Metamod-based extension */ - virtual bool IsMetamodExtension(); - - /** - * @brief Called when the pause state changes. - * - * @param state True if being paused, false if being unpaused. - */ - virtual void OnExtensionPauseChange(bool state); - - /** Returns name */ - virtual const char *GetExtensionName(); - /** Returns URL */ - virtual const char *GetExtensionURL(); - /** Returns log tag */ - virtual const char *GetExtensionTag(); - /** Returns author */ - virtual const char *GetExtensionAuthor(); - /** Returns version string */ - virtual const char *GetExtensionVerString(); - /** Returns description string */ - virtual const char *GetExtensionDescription(); - /** Returns date string */ - virtual const char *GetExtensionDateString(); -#if defined SMEXT_CONF_METAMOD -public: // ISmmPlugin - /** Called when the extension is attached to Metamod. */ - virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late); - /** Returns the author to MM */ - virtual const char *GetAuthor(); - /** Returns the name to MM */ - virtual const char *GetName(); - /** Returns the description to MM */ - virtual const char *GetDescription(); - /** Returns the URL to MM */ - virtual const char *GetURL(); - /** Returns the license to MM */ - virtual const char *GetLicense(); - /** Returns the version string to MM */ - virtual const char *GetVersion(); - /** Returns the date string to MM */ - virtual const char *GetDate(); - /** Returns the logtag to MM */ - virtual const char *GetLogTag(); - /** Called on unload */ - virtual bool Unload(char *error, size_t maxlen); - /** Called on pause */ - virtual bool Pause(char *error, size_t maxlen); - /** Called on unpause */ - virtual bool Unpause(char *error, size_t maxlen); -private: - bool m_SourceMMLoaded; - bool m_WeAreUnloaded; - bool m_WeGotPauseChange; -#endif -}; - -extern SDKExtension *g_pExtensionIface; - -extern IShareSys *g_pShareSys; -extern IExtension *myself; -extern IHandleSys *g_pHandleSys; -extern ISourceMod *g_pSM; -extern IForwardManager *g_pForwards; - -#if defined SMEXT_CONF_METAMOD -PLUGIN_GLOBALVARS(); -extern IVEngineServer *engine; -extern IServerGameDLL *gamedll; -#endif - -/** Creates a SourceMod interface macro pair */ -#define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION -/** Automates retrieving SourceMod interfaces */ -#define SM_GET_IFACE(prefix, addr) \ - if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \ - { \ - if (error) \ - { \ - snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ - return false; \ - } \ - } -/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */ -#define SM_GET_LATE_IFACE(prefix, addr) \ - g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr) -/** Validates a SourceMod interface pointer */ -#define SM_CHECK_IFACE(prefix, addr) \ - if (!addr) \ - { \ - if (error) \ - { \ - snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ - return false; \ - } \ - } - -#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ diff --git a/extensions/threader/svn_version.h b/extensions/threader/svn_version.h deleted file mode 100644 index 599ca1a5..00000000 --- a/extensions/threader/svn_version.h +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Autogenerated by build scripts - */ - -#ifndef _INCLUDE_THREADER_VERSION_H_ -#define _INCLUDE_THREADER_VERSION_H_ - - -#define SVN_FULL_VERSION "1.0.0.431" -#define SVN_FILE_VERSION 1,0,0,431 - -#endif //_INCLUDE_THREADER_VERSION_H_ diff --git a/extensions/threader/svn_version.tpl b/extensions/threader/svn_version.tpl deleted file mode 100644 index 822b671f..00000000 --- a/extensions/threader/svn_version.tpl +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Autogenerated by build scripts - */ - -#ifndef _INCLUDE_THREADER_VERSION_H_ -#define _INCLUDE_THREADER_VERSION_H_ - - -#define SVN_FULL_VERSION "$PMAJOR$.$PMINOR$.$PREVISION$.$LOCAL_BUILD$" -#define SVN_FILE_VERSION $PMAJOR$,$PMINOR$,$PREVISION$,$LOCAL_BUILD$ - -#endif //_INCLUDE_THREADER_VERSION_H_ diff --git a/extensions/threader/thread/BaseWorker.cpp b/extensions/threader/thread/BaseWorker.cpp deleted file mode 100644 index 5f632875..00000000 --- a/extensions/threader/thread/BaseWorker.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#include "BaseWorker.h" - -BaseWorker::BaseWorker() : - m_perFrame(SM_DEFAULT_THREADS_PER_FRAME), - m_state(Worker_Stopped) -{ -} - -BaseWorker::~BaseWorker() -{ - if (m_state != Worker_Stopped || m_state != Worker_Invalid) - Stop(true); - - if (m_ThreadQueue.size()) - Flush(true); -} - -void BaseWorker::MakeThread(IThread *pThread) -{ - ThreadParams pt; - - pt.flags = Thread_AutoRelease; - pt.prio = ThreadPrio_Normal; - - MakeThread(pThread, &pt); -} - -IThreadHandle *BaseWorker::MakeThread(IThread *pThread, ThreadFlags flags) -{ - ThreadParams pt; - - pt.flags = flags; - pt.prio = ThreadPrio_Normal; - - return MakeThread(pThread, &pt); -} - -IThreadHandle *BaseWorker::MakeThread(IThread *pThread, const ThreadParams *params) -{ - if (m_state != Worker_Running) - return NULL; - - SWThreadHandle *swt = new SWThreadHandle(this, params, pThread); - - AddThreadToQueue(swt); - - return swt; -} - -void BaseWorker::GetPriorityBounds(ThreadPriority &max, ThreadPriority &min) -{ - max = ThreadPrio_Normal; - min = ThreadPrio_Normal; -} - -unsigned int BaseWorker::Flush(bool flush_cancel) -{ - SWThreadHandle *swt; - unsigned int num = 0; - - while ((swt=PopThreadFromQueue()) != NULL) - { - swt->m_state = Thread_Done; - if (!flush_cancel) - swt->pThread->RunThread(swt); - swt->pThread->OnTerminate(swt, flush_cancel); - if (swt->m_params.flags & Thread_AutoRelease) - delete swt; - num++; - } - - return num; -} - -SWThreadHandle *BaseWorker::PopThreadFromQueue() -{ - if (!m_ThreadQueue.size()) - return NULL; - - SourceHook::List::iterator begin; - SWThreadHandle *swt; - - begin = m_ThreadQueue.begin(); - swt = (*begin); - m_ThreadQueue.erase(begin); - - return swt; -} - -void BaseWorker::AddThreadToQueue(SWThreadHandle *pHandle) -{ - m_ThreadQueue.push_back(pHandle); -} - -unsigned int BaseWorker::GetMaxThreadsPerFrame() -{ - return m_perFrame; -} - -WorkerState BaseWorker::GetStatus(unsigned int *threads) -{ - if (threads) - *threads = m_perFrame; - - return m_state; -} - -unsigned int BaseWorker::RunFrame() -{ - unsigned int done = 0; - unsigned int max = GetMaxThreadsPerFrame(); - SWThreadHandle *swt = NULL; - IThread *pThread = NULL; - - while (done < max) - { - if ((swt=PopThreadFromQueue()) == NULL) - break; - pThread = swt->pThread; - swt->m_state = Thread_Running; - pThread->RunThread(swt); - swt->m_state = Thread_Done; - pThread->OnTerminate(swt, false); - if (swt->m_params.flags & Thread_AutoRelease) - delete swt; - done++; - } - - return done; -} - -void BaseWorker::SetMaxThreadsPerFrame(unsigned int threads) -{ - m_perFrame = threads; -} - -bool BaseWorker::Start() -{ - if (m_state != Worker_Invalid && m_state != Worker_Stopped) - { - return false; - } - - m_state = Worker_Running; - - return true; -} - -bool BaseWorker::Stop(bool flush_cancel) -{ - if (m_state == Worker_Invalid || m_state == Worker_Stopped) - return false; - - if (m_state == Worker_Paused) - { - if (!Unpause()) - return false; - } - - m_state = Worker_Stopped; - Flush(flush_cancel); - - return true; -} - -bool BaseWorker::Pause() -{ - if (m_state != Worker_Running) - return false; - - m_state = Worker_Paused; - - return true; -} - - -bool BaseWorker::Unpause() -{ - if (m_state != Worker_Paused) - return false; - - m_state = Worker_Running; - - return true; -} - -/*********************** - * THREAD HANDLE STUFF * - ***********************/ - -void SWThreadHandle::DestroyThis() -{ - delete this; -} - -void SWThreadHandle::GetParams(ThreadParams *p) -{ - *p = m_params; -} - -ThreadPriority SWThreadHandle::GetPriority() -{ - return m_params.prio; -} - -ThreadState SWThreadHandle::GetState() -{ - return m_state; -} - -IThreadCreator *SWThreadHandle::Parent() -{ - return m_parent; -} - -bool SWThreadHandle::SetPriority(ThreadPriority prio) -{ - if (m_params.prio != ThreadPrio_Normal) - return false; - - m_params.prio = prio; - - return true; -} - -bool SWThreadHandle::Unpause() -{ - if (m_state != Thread_Paused) - return false; - - m_state = Thread_Running; - - return true; -} - -bool SWThreadHandle::WaitForThread() -{ - return false; -} - -SWThreadHandle::SWThreadHandle(IThreadCreator *parent, const ThreadParams *p, IThread *thread) : - m_state(Thread_Paused), m_params(*p), m_parent(parent), pThread(thread) -{ -} - -IThread *SWThreadHandle::GetThread() -{ - return pThread; -} diff --git a/extensions/threader/thread/BaseWorker.h b/extensions/threader/thread/BaseWorker.h deleted file mode 100644 index 65e875a2..00000000 --- a/extensions/threader/thread/BaseWorker.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_BASEWORKER_H -#define _INCLUDE_SOURCEMOD_BASEWORKER_H - -#include "sh_list.h" -#include "ThreadSupport.h" - -#define SM_DEFAULT_THREADS_PER_FRAME 1 - -class BaseWorker; - -//SW = Simple Wrapper -class SWThreadHandle : public IThreadHandle -{ - friend class BaseWorker; -public: - SWThreadHandle(IThreadCreator *parent, const ThreadParams *p, IThread *thread); - IThread *GetThread(); -public: - //NOTE: We don't support this by default. - //It's specific usage that'd require many mutexes - virtual bool WaitForThread(); -public: - virtual void DestroyThis(); - virtual IThreadCreator *Parent(); - virtual void GetParams(ThreadParams *ptparams); -public: - //Priorities not supported by default. - virtual ThreadPriority GetPriority(); - virtual bool SetPriority(ThreadPriority prio); -public: - virtual ThreadState GetState(); - virtual bool Unpause(); -private: - ThreadState m_state; - ThreadParams m_params; - IThreadCreator *m_parent; - IThread *pThread; -}; - -class BaseWorker : public IThreadWorker -{ -public: - BaseWorker(); - virtual ~BaseWorker(); -public: //IWorker - virtual unsigned int RunFrame(); - //Controls the worker - virtual bool Pause(); - virtual bool Unpause(); - virtual bool Start(); - virtual bool Stop(bool flush_cancel); - //Flushes out any remaining threads - virtual unsigned int Flush(bool flush_cancel); - //returns status and number of threads in queue - virtual WorkerState GetStatus(unsigned int *numThreads); -public: //IThreadCreator - virtual void MakeThread(IThread *pThread); - virtual IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags); - virtual IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params); - virtual void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min); -public: //BaseWorker - virtual void AddThreadToQueue(SWThreadHandle *pHandle); - virtual SWThreadHandle *PopThreadFromQueue(); - virtual void SetMaxThreadsPerFrame(unsigned int threads); - virtual unsigned int GetMaxThreadsPerFrame(); -protected: - SourceHook::List m_ThreadQueue; - unsigned int m_perFrame; - volatile WorkerState m_state; -}; - -#endif //_INCLUDE_SOURCEMOD_BASEWORKER_H diff --git a/extensions/threader/thread/PosixThreads.cpp b/extensions/threader/thread/PosixThreads.cpp deleted file mode 100644 index b2a30aca..00000000 --- a/extensions/threader/thread/PosixThreads.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#include -#include "PosixThreads.h" -#include "ThreadWorker.h" - -IThreadWorker *PosixThreader::MakeWorker(bool threaded) -{ - if (threaded) - { - return new ThreadWorker(this, DEFAULT_THINK_TIME_MS); - } else { - return new BaseWorker(); - } -} - -void PosixThreader::DestroyWorker(IThreadWorker *pWorker) -{ - delete pWorker; -} - -void PosixThreader::ThreadSleep(unsigned int ms) -{ - usleep( ms * 1000 ); -} - -void PosixThreader::GetPriorityBounds(ThreadPriority &max, ThreadPriority &min) -{ - max = ThreadPrio_Normal; - min = ThreadPrio_Normal; -} - -IMutex *PosixThreader::MakeMutex() -{ - pthread_mutex_t mutex; - - if (pthread_mutex_init(&mutex, NULL) != 0) - return NULL; - - PosixMutex *pMutex = new PosixMutex(mutex); - - return pMutex; -} - - -void PosixThreader::MakeThread(IThread *pThread) -{ - ThreadParams defparams; - - defparams.flags = Thread_AutoRelease; - defparams.prio = ThreadPrio_Normal; - - MakeThread(pThread, &defparams); -} - -IThreadHandle *PosixThreader::MakeThread(IThread *pThread, ThreadFlags flags) -{ - ThreadParams defparams; - - defparams.flags = flags; - defparams.prio = ThreadPrio_Normal; - - return MakeThread(pThread, &defparams); -} - -void *Posix_ThreadGate(void *param) -{ - PosixThreader::ThreadHandle *pHandle = - reinterpret_cast(param); - - //Block this thread from being started initially. - pthread_mutex_lock(&pHandle->m_runlock); - //if we get here, we've obtained the lock and are allowed to run. - //unlock and continue. - pthread_mutex_unlock(&pHandle->m_runlock); - - pHandle->m_run->RunThread(pHandle); - - ThreadParams params; - pthread_mutex_lock(&pHandle->m_statelock); - pHandle->m_state = Thread_Done; - pHandle->GetParams(¶ms); - pthread_mutex_unlock(&pHandle->m_statelock); - - pHandle->m_run->OnTerminate(pHandle, false); - if (params.flags & Thread_AutoRelease) - delete pHandle; - - return 0; -} - -ThreadParams g_defparams; -IThreadHandle *PosixThreader::MakeThread(IThread *pThread, const ThreadParams *params) -{ - if (params == NULL) - params = &g_defparams; - - PosixThreader::ThreadHandle *pHandle = - new PosixThreader::ThreadHandle(this, pThread, params); - - pthread_mutex_lock(&pHandle->m_runlock); - - int err; - err = pthread_create(&pHandle->m_thread, NULL, Posix_ThreadGate, (void *)pHandle); - - if (err != 0) - { - pthread_mutex_unlock(&pHandle->m_runlock); - delete pHandle; - return NULL; - } - - //Don't bother setting priority... - - if (!(pHandle->m_params.flags & Thread_CreateSuspended)) - { - pHandle->m_state = Thread_Running; - err = pthread_mutex_unlock(&pHandle->m_runlock); - if (err != 0) - pHandle->m_state = Thread_Paused; - } - - return pHandle; -} - -IEventSignal *PosixThreader::MakeEventSignal() -{ - return new PosixEventSignal(); -} - -/***************** -**** Mutexes **** -*****************/ - -PosixThreader::PosixMutex::~PosixMutex() -{ - pthread_mutex_destroy(&m_mutex); -} - -bool PosixThreader::PosixMutex::TryLock() -{ - int err = pthread_mutex_trylock(&m_mutex); - - return (err == 0); -} - -void PosixThreader::PosixMutex::Lock() -{ - pthread_mutex_lock(&m_mutex); -} - -void PosixThreader::PosixMutex::Unlock() -{ - pthread_mutex_unlock(&m_mutex); -} - -void PosixThreader::PosixMutex::DestroyThis() -{ - delete this; -} - -/****************** -* Thread Handles * -******************/ - -PosixThreader::ThreadHandle::ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params) : - m_parent(parent), m_params(*params), m_run(run), m_state(Thread_Paused) -{ - pthread_mutex_init(&m_runlock, NULL); - pthread_mutex_init(&m_statelock, NULL); -} - -PosixThreader::ThreadHandle::~ThreadHandle() -{ - pthread_mutex_destroy(&m_runlock); - pthread_mutex_destroy(&m_statelock); -} - -bool PosixThreader::ThreadHandle::WaitForThread() -{ - void *arg; - - if (pthread_join(m_thread, &arg) != 0) - return false; - - return true; -} - -ThreadState PosixThreader::ThreadHandle::GetState() -{ - ThreadState state; - - pthread_mutex_lock(&m_statelock); - state = m_state; - pthread_mutex_unlock(&m_statelock); - - return state; -} - -IThreadCreator *PosixThreader::ThreadHandle::Parent() -{ - return m_parent; -} - -void PosixThreader::ThreadHandle::DestroyThis() -{ - if (m_params.flags & Thread_AutoRelease) - return; - - delete this; -} - -void PosixThreader::ThreadHandle::GetParams(ThreadParams *ptparams) -{ - if (!ptparams) - return; - - *ptparams = m_params; -} - -ThreadPriority PosixThreader::ThreadHandle::GetPriority() -{ - return ThreadPrio_Normal; -} - -bool PosixThreader::ThreadHandle::SetPriority(ThreadPriority prio) -{ - return (prio == ThreadPrio_Normal); -} - -bool PosixThreader::ThreadHandle::Unpause() -{ - if (m_state != Thread_Paused) - return false; - - m_state = Thread_Running; - - if (pthread_mutex_unlock(&m_runlock) != 0) - { - m_state = Thread_Paused; - return false; - } - - return true; -} - -/***************** - * EVENT SIGNALS * - *****************/ - -PosixThreader::PosixEventSignal::PosixEventSignal() -{ - pthread_cond_init(&m_cond, NULL); - pthread_mutex_init(&m_mutex, NULL); -} - -PosixThreader::PosixEventSignal::~PosixEventSignal() -{ - pthread_cond_destroy(&m_cond); - pthread_mutex_destroy(&m_mutex); -} - -void PosixThreader::PosixEventSignal::Wait() -{ - pthread_mutex_lock(&m_mutex); - pthread_cond_wait(&m_cond, &m_mutex); - pthread_mutex_unlock(&m_mutex); -} - -void PosixThreader::PosixEventSignal::Signal() -{ - pthread_mutex_lock(&m_mutex); - pthread_cond_broadcast(&m_cond); - pthread_mutex_unlock(&m_mutex); -} - -void PosixThreader::PosixEventSignal::DestroyThis() -{ - delete this; -} diff --git a/extensions/threader/thread/PosixThreads.h b/extensions/threader/thread/PosixThreads.h deleted file mode 100644 index efa4248a..00000000 --- a/extensions/threader/thread/PosixThreads.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_POSIXTHREADS_H_ -#define _INCLUDE_POSIXTHREADS_H_ - -#include -#include "IThreader.h" - -using namespace SourceMod; - -void *Posix_ThreadGate(void *param); - -class PosixThreader : public IThreader -{ -public: - class ThreadHandle : public IThreadHandle - { - friend class PosixThreader; - friend void *Posix_ThreadGate(void *param); - public: - ThreadHandle(IThreader *parent, IThread *run, const ThreadParams *params); - virtual ~ThreadHandle(); - public: - virtual bool WaitForThread(); - virtual void DestroyThis(); - virtual IThreadCreator *Parent(); - virtual void GetParams(ThreadParams *ptparams); - virtual ThreadPriority GetPriority(); - virtual bool SetPriority(ThreadPriority prio); - virtual ThreadState GetState(); - virtual bool Unpause(); - protected: - IThreader *m_parent; //Parent handle - pthread_t m_thread; //Windows HANDLE - ThreadParams m_params; //Current Parameters - IThread *m_run; //Runnable context - pthread_mutex_t m_statelock; - pthread_mutex_t m_runlock; - ThreadState m_state; //internal state - }; - class PosixMutex : public IMutex - { - public: - PosixMutex(pthread_mutex_t m) : m_mutex(m) - { - }; - virtual ~PosixMutex(); - public: - virtual bool TryLock(); - virtual void Lock(); - virtual void Unlock(); - virtual void DestroyThis(); - protected: - pthread_mutex_t m_mutex; - }; - class PosixEventSignal : public IEventSignal - { - public: - PosixEventSignal(); - virtual ~PosixEventSignal(); - public: - virtual void Wait(); - virtual void Signal(); - virtual void DestroyThis(); - protected: - pthread_cond_t m_cond; - pthread_mutex_t m_mutex; - }; -public: - IMutex *MakeMutex(); - void MakeThread(IThread *pThread); - IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags); - IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params); - void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min); - void ThreadSleep(unsigned int ms); - IEventSignal *MakeEventSignal(); - IThreadWorker *MakeWorker(bool threaded); - void DestroyWorker(IThreadWorker *pWorker); -}; - -#if defined SM_DEFAULT_THREADER && !defined SM_MAIN_THREADER -#define SM_MAIN_THREADER PosixThreader; -typedef class PosixThreader MainThreader; -#endif - -#endif //_INCLUDE_POSIXTHREADS_H_ diff --git a/extensions/threader/thread/ThreadSupport.h b/extensions/threader/thread/ThreadSupport.h deleted file mode 100644 index f87cf548..00000000 --- a/extensions/threader/thread/ThreadSupport.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_THREAD_SUPPORT_H -#define _INCLUDE_SOURCEMOD_THREAD_SUPPORT_H - -#if defined __linux__ -#include "PosixThreads.h" -#elif defined WIN32 -#include "WinThreads.h" -#endif - -#endif //_INCLUDE_SOURCEMOD_THREAD_SUPPORT_H diff --git a/extensions/threader/thread/ThreadWorker.cpp b/extensions/threader/thread/ThreadWorker.cpp deleted file mode 100644 index 32e2e757..00000000 --- a/extensions/threader/thread/ThreadWorker.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#include "ThreadWorker.h" - -ThreadWorker::ThreadWorker() : - m_Threader(NULL), - m_QueueLock(NULL), - m_StateLock(NULL), - m_PauseSignal(NULL), - m_AddSignal(NULL), - me(NULL), - m_think_time(DEFAULT_THINK_TIME_MS) -{ - m_state = Worker_Invalid; -} - -ThreadWorker::ThreadWorker(IThreader *pThreader, unsigned int thinktime) : - m_Threader(pThreader), - m_QueueLock(NULL), - m_StateLock(NULL), - m_PauseSignal(NULL), - m_AddSignal(NULL), - me(NULL), - m_think_time(thinktime) -{ - if (m_Threader) - { - m_state = Worker_Stopped; - } else { - m_state = Worker_Invalid; - } -} - -ThreadWorker::~ThreadWorker() -{ - if (m_state != Worker_Stopped || m_state != Worker_Invalid) - Stop(true); - - if (m_ThreadQueue.size()) - Flush(true); -} - -void ThreadWorker::OnTerminate(IThreadHandle *pHandle, bool cancel) -{ - //we don't particularly care - return; -} - -void ThreadWorker::RunThread(IThreadHandle *pHandle) -{ - WorkerState this_state = Worker_Running; - size_t num; - - while (true) - { - /** - * Check number of items in the queue - */ - m_StateLock->Lock(); - this_state = m_state; - m_StateLock->Unlock(); - if (this_state != Worker_Stopped) - { - m_QueueLock->Lock(); - num = m_ThreadQueue.size(); - if (!num) - { - /** - * if none, wait for an item - */ - m_Waiting = true; - m_QueueLock->Unlock(); - /* first check if we should end again */ - if (this_state == Worker_Stopped) - { - break; - } - m_AddSignal->Wait(); - m_Waiting = false; - } else { - m_QueueLock->Unlock(); - } - } - m_StateLock->Lock(); - this_state = m_state; - m_StateLock->Unlock(); - if (this_state != Worker_Running) - { - if (this_state == Worker_Paused || this_state == Worker_Stopped) - { - //wait until the lock is cleared. - if (this_state == Worker_Paused) - { - m_PauseSignal->Wait(); - } - if (this_state == Worker_Stopped) - { - //if we're supposed to flush cleanrly, - // run all of the remaining frames first. - if (!m_FlushType) - { - while (m_ThreadQueue.size()) - RunFrame(); - } - break; - } - } - } - /** - * Run the frame. - */ - RunFrame(); - - /** - * wait in between threads if specified - */ - if (m_think_time) - m_Threader->ThreadSleep(m_think_time); - } -} - -SWThreadHandle *ThreadWorker::PopThreadFromQueue() -{ - if (m_state <= Worker_Stopped && !m_QueueLock) - return NULL; - - SWThreadHandle *swt; - m_QueueLock->Lock(); - swt = BaseWorker::PopThreadFromQueue(); - m_QueueLock->Unlock(); - - return swt; -} - -void ThreadWorker::AddThreadToQueue(SWThreadHandle *pHandle) -{ - if (m_state <= Worker_Stopped) - return; - - m_QueueLock->Lock(); - BaseWorker::AddThreadToQueue(pHandle); - if (m_Waiting) - { - m_AddSignal->Signal(); - } - m_QueueLock->Unlock(); -} - -WorkerState ThreadWorker::GetStatus(unsigned int *threads) -{ - WorkerState state; - - m_StateLock->Lock(); - state = BaseWorker::GetStatus(threads); - m_StateLock->Unlock(); - - return state; -} - -bool ThreadWorker::Start() -{ - if (m_state == Worker_Invalid) - { - if (m_Threader == NULL) - return false; - } else if (m_state != Worker_Stopped) { - return false; - } - - m_Waiting = false; - m_QueueLock = m_Threader->MakeMutex(); - m_StateLock = m_Threader->MakeMutex(); - m_PauseSignal = m_Threader->MakeEventSignal(); - m_AddSignal = m_Threader->MakeEventSignal(); - m_state = Worker_Running; - ThreadParams pt; - pt.flags = Thread_Default; - pt.prio = ThreadPrio_Normal; - me = m_Threader->MakeThread(this, &pt); - - return true; -} - -bool ThreadWorker::Stop(bool flush_cancel) -{ - if (m_state == Worker_Invalid || m_state == Worker_Stopped) - return false; - - WorkerState oldstate; - - //set new state - m_StateLock->Lock(); - oldstate = m_state; - m_state = Worker_Stopped; - m_FlushType = flush_cancel; - m_StateLock->Unlock(); - - if (oldstate == Worker_Paused) - { - Unpause(); - } else { - m_QueueLock->Lock(); - if (m_Waiting) - { - m_AddSignal->Signal(); - } - m_QueueLock->Unlock(); - } - - me->WaitForThread(); - //destroy it - me->DestroyThis(); - //flush all remaining events - Flush(true); - - //free mutex locks - m_QueueLock->DestroyThis(); - m_StateLock->DestroyThis(); - m_PauseSignal->DestroyThis(); - m_AddSignal->DestroyThis(); - - //invalidizzle - m_QueueLock = NULL; - m_StateLock = NULL; - m_PauseSignal = NULL; - m_AddSignal = NULL; - me = NULL; - - return true; -} - -bool ThreadWorker::Pause() -{ - if (m_state != Worker_Running) - return false; - - m_StateLock->Lock(); - m_state = Worker_Paused; - m_StateLock->Unlock(); - - return true; -} - - -bool ThreadWorker::Unpause() -{ - if (m_state != Worker_Paused) - return false; - - m_StateLock->Lock(); - m_state = Worker_Running; - m_StateLock->Unlock(); - m_PauseSignal->Signal(); - if (m_Waiting) - { - m_AddSignal->Signal(); - } - - return true; -} diff --git a/extensions/threader/thread/ThreadWorker.h b/extensions/threader/thread/ThreadWorker.h deleted file mode 100644 index bdf2e949..00000000 --- a/extensions/threader/thread/ThreadWorker.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_THREADWORKER_H -#define _INCLUDE_SOURCEMOD_THREADWORKER_H - -#include "BaseWorker.h" - -#define DEFAULT_THINK_TIME_MS 500 - -class ThreadWorker : public BaseWorker, public IThread -{ -public: - ThreadWorker(); - ThreadWorker(IThreader *pThreader, unsigned int thinktime=DEFAULT_THINK_TIME_MS); - virtual ~ThreadWorker(); -public: //IThread - virtual void OnTerminate(IThreadHandle *pHandle, bool cancel); - virtual void RunThread(IThreadHandle *pHandle); -public: //IWorker - //Controls the worker - virtual bool Pause(); - virtual bool Unpause(); - virtual bool Start(); - virtual bool Stop(bool flush_cancel); - //returns status and number of threads in queue - virtual WorkerState GetStatus(unsigned int *numThreads); -public: //BaseWorker - virtual void AddThreadToQueue(SWThreadHandle *pHandle); - virtual SWThreadHandle *PopThreadFromQueue(); -protected: - IThreader *m_Threader; - IMutex *m_QueueLock; - IMutex *m_StateLock; - IEventSignal *m_PauseSignal; - IEventSignal *m_AddSignal; - IThreadHandle *me; - unsigned int m_think_time; - volatile bool m_Waiting; - volatile bool m_FlushType; -}; - -#endif //_INCLUDE_SOURCEMOD_THREADWORKER_H diff --git a/extensions/threader/thread/WinThreads.cpp b/extensions/threader/thread/WinThreads.cpp deleted file mode 100644 index 9798e6db..00000000 --- a/extensions/threader/thread/WinThreads.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#include "WinThreads.h" -#include "ThreadWorker.h" - -IThreadWorker *WinThreader::MakeWorker(bool threaded) -{ - if (threaded) - { - return new ThreadWorker(this, DEFAULT_THINK_TIME_MS); - } else { - return new BaseWorker(); - } -} - -void WinThreader::DestroyWorker(IThreadWorker *pWorker) -{ - delete pWorker; -} - -void WinThreader::ThreadSleep(unsigned int ms) -{ - Sleep((DWORD)ms); -} - -IMutex *WinThreader::MakeMutex() -{ - HANDLE mutex = CreateMutexA(NULL, FALSE, NULL); - - if (mutex == NULL) - return NULL; - - WinMutex *pMutex = new WinMutex(mutex); - - return pMutex; -} - -IThreadHandle *WinThreader::MakeThread(IThread *pThread, ThreadFlags flags) -{ - ThreadParams defparams; - - defparams.flags = flags; - defparams.prio = ThreadPrio_Normal; - - return MakeThread(pThread, &defparams); -} - -void WinThreader::MakeThread(IThread *pThread) -{ - ThreadParams defparams; - - defparams.flags = Thread_AutoRelease; - defparams.prio = ThreadPrio_Normal; - - MakeThread(pThread, &defparams); -} - -DWORD WINAPI Win32_ThreadGate(LPVOID param) -{ - WinThreader::ThreadHandle *pHandle = - reinterpret_cast(param); - - pHandle->m_run->RunThread(pHandle); - - ThreadParams params; - EnterCriticalSection(&pHandle->m_crit); - pHandle->m_state = Thread_Done; - pHandle->GetParams(¶ms); - LeaveCriticalSection(&pHandle->m_crit); - - pHandle->m_run->OnTerminate(pHandle, false); - if (params.flags & Thread_AutoRelease) - delete pHandle; - - return 0; -} - -void WinThreader::GetPriorityBounds(ThreadPriority &max, ThreadPriority &min) -{ - max = ThreadPrio_Maximum; - min = ThreadPrio_Minimum; -} - -ThreadParams g_defparams; -IThreadHandle *WinThreader::MakeThread(IThread *pThread, const ThreadParams *params) -{ - if (params == NULL) - params = &g_defparams; - - WinThreader::ThreadHandle *pHandle = - new WinThreader::ThreadHandle(this, NULL, pThread, params); - - DWORD tid; - pHandle->m_thread = - CreateThread(NULL, 0, &Win32_ThreadGate, (LPVOID)pHandle, CREATE_SUSPENDED, &tid); - - if (!pHandle->m_thread) - { - delete pHandle; - return NULL; - } - - if (pHandle->m_params.prio != ThreadPrio_Normal) - { - pHandle->SetPriority(pHandle->m_params.prio); - } - - if (!(pHandle->m_params.flags & Thread_CreateSuspended)) - { - pHandle->Unpause(); - } - - return pHandle; -} - -IEventSignal *WinThreader::MakeEventSignal() -{ - HANDLE event = CreateEventA(NULL, FALSE, FALSE, NULL); - - if (!event) - return NULL; - - WinEvent *pEvent = new WinEvent(event); - - return pEvent; -} - -/***************** - **** Mutexes **** - *****************/ - -WinThreader::WinMutex::~WinMutex() -{ - if (m_mutex) - { - CloseHandle(m_mutex); - m_mutex = NULL; - } -} - -bool WinThreader::WinMutex::TryLock() -{ - if (!m_mutex) - return false; - - if (WaitForSingleObject(m_mutex, 0) != WAIT_FAILED) - return true; - - return false; -} - -void WinThreader::WinMutex::Lock() -{ - if (!m_mutex) - return; - - WaitForSingleObject(m_mutex, INFINITE); -} - -void WinThreader::WinMutex::Unlock() -{ - if (!m_mutex) - return; - - ReleaseMutex(m_mutex); -} - -void WinThreader::WinMutex::DestroyThis() -{ - delete this; -} - -/****************** - * Thread Handles * - ******************/ - -WinThreader::ThreadHandle::ThreadHandle(IThreader *parent, HANDLE hthread, IThread *run, const ThreadParams *params) : - m_parent(parent), m_thread(hthread), m_run(run), m_params(*params), - m_state(Thread_Paused) -{ - InitializeCriticalSection(&m_crit); -} - -WinThreader::ThreadHandle::~ThreadHandle() -{ - if (m_thread) - { - CloseHandle(m_thread); - m_thread = NULL; - } - DeleteCriticalSection(&m_crit); -} - -bool WinThreader::ThreadHandle::WaitForThread() -{ - if (m_thread == NULL) - return false; - - if (WaitForSingleObject(m_thread, INFINITE) != 0) - return false; - - return true; -} - -ThreadState WinThreader::ThreadHandle::GetState() -{ - ThreadState state; - - EnterCriticalSection(&m_crit); - state = m_state; - LeaveCriticalSection(&m_crit); - - return state; -} - -IThreadCreator *WinThreader::ThreadHandle::Parent() -{ - return m_parent; -} - -void WinThreader::ThreadHandle::DestroyThis() -{ - if (m_params.flags & Thread_AutoRelease) - return; - - delete this; -} - -void WinThreader::ThreadHandle::GetParams(ThreadParams *ptparams) -{ - if (!ptparams) - return; - - *ptparams = m_params; -} - -ThreadPriority WinThreader::ThreadHandle::GetPriority() -{ - return m_params.prio; -} - -bool WinThreader::ThreadHandle::SetPriority(ThreadPriority prio) -{ - if (!m_thread) - return false; - - BOOL res = FALSE; - - if (prio >= ThreadPrio_Maximum) - res = SetThreadPriority(m_thread, THREAD_PRIORITY_HIGHEST); - else if (prio <= ThreadPrio_Minimum) - res = SetThreadPriority(m_thread, THREAD_PRIORITY_LOWEST); - else if (prio == ThreadPrio_Normal) - res = SetThreadPriority(m_thread, THREAD_PRIORITY_NORMAL); - else if (prio == ThreadPrio_High) - res = SetThreadPriority(m_thread, THREAD_PRIORITY_ABOVE_NORMAL); - else if (prio == ThreadPrio_Low) - res = SetThreadPriority(m_thread, THREAD_PRIORITY_BELOW_NORMAL); - - m_params.prio = prio; - - return (res != FALSE); -} - -bool WinThreader::ThreadHandle::Unpause() -{ - if (!m_thread) - return false; - - if (m_state != Thread_Paused) - return false; - - m_state = Thread_Running; - - if (ResumeThread(m_thread) == -1) - { - m_state = Thread_Paused; - return false; - } - - return true; -} - -/***************** - * EVENT SIGNALS * - *****************/ - -WinThreader::WinEvent::~WinEvent() -{ - CloseHandle(m_event); -} - -void WinThreader::WinEvent::Wait() -{ - WaitForSingleObject(m_event, INFINITE); -} - -void WinThreader::WinEvent::Signal() -{ - SetEvent(m_event); -} - -void WinThreader::WinEvent::DestroyThis() -{ - delete this; -} diff --git a/extensions/threader/thread/WinThreads.h b/extensions/threader/thread/WinThreads.h deleted file mode 100644 index a5fa4a25..00000000 --- a/extensions/threader/thread/WinThreads.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - * vim: set ts=4 : - * =============================================================== - * SourceMod Threader API - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * =============================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_WINTHREADS_H_ -#define _INCLUDE_WINTHREADS_H_ - -#include -#include "IThreader.h" - -using namespace SourceMod; - -DWORD WINAPI Win32_ThreadGate(LPVOID param); - -class WinThreader : public IThreader -{ -public: - class ThreadHandle : public IThreadHandle - { - friend class WinThreader; - friend DWORD WINAPI Win32_ThreadGate(LPVOID param); - public: - ThreadHandle(IThreader *parent, HANDLE hthread, IThread *run, const ThreadParams *params); - virtual ~ThreadHandle(); - public: - virtual bool WaitForThread(); - virtual void DestroyThis(); - virtual IThreadCreator *Parent(); - virtual void GetParams(ThreadParams *ptparams); - virtual ThreadPriority GetPriority(); - virtual bool SetPriority(ThreadPriority prio); - virtual ThreadState GetState(); - virtual bool Unpause(); - protected: - IThreader *m_parent; //Parent handle - HANDLE m_thread; //Windows HANDLE - ThreadParams m_params; //Current Parameters - IThread *m_run; //Runnable context - ThreadState m_state; //internal state - CRITICAL_SECTION m_crit; - }; - class WinMutex : public IMutex - { - public: - WinMutex(HANDLE mutex) : m_mutex(mutex) - { - }; - virtual ~WinMutex(); - public: - virtual bool TryLock(); - virtual void Lock(); - virtual void Unlock(); - virtual void DestroyThis(); - protected: - HANDLE m_mutex; - }; - class WinEvent : public IEventSignal - { - public: - WinEvent(HANDLE event) : m_event(event) - { - }; - virtual ~WinEvent(); - public: - virtual void Wait(); - virtual void Signal(); - virtual void DestroyThis(); - public: - HANDLE m_event; - }; -public: - IMutex *MakeMutex(); - void MakeThread(IThread *pThread); - IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags); - IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params); - void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min); - void ThreadSleep(unsigned int ms); - IEventSignal *MakeEventSignal(); - IThreadWorker *MakeWorker(bool threaded); - void DestroyWorker(IThreadWorker *pWorker); -}; - -#if defined SM_DEFAULT_THREADER && !defined SM_MAIN_THREADER -#define SM_MAIN_THREADER WinThreader; -typedef class WinThreader MainThreader; -#endif - -#endif //_INCLUDE_WINTHREADS_H_ diff --git a/extensions/threader/version.rc b/extensions/threader/version.rc deleted file mode 100644 index 0694a0e7..00000000 --- a/extensions/threader/version.rc +++ /dev/null @@ -1,104 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -//#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winres.h" - -#include "svn_version.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION SVN_FILE_VERSION - PRODUCTVERSION SVN_FILE_VERSION - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "Comments", "Threader Extension" - VALUE "FileDescription", "SourceMod Threader Extension" - VALUE "FileVersion", SVN_FULL_VERSION - VALUE "InternalName", "SourceMod Threader Extension" - VALUE "LegalCopyright", "Copyright (c) 2004-2007, AlliedModders LLC" - VALUE "OriginalFilename", "threader.ext.dll" - VALUE "ProductName", "SourceMod Threader Extension" - VALUE "ProductVersion", SVN_FULL_VERSION - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""winres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED -