- added callback functionality to IThreadWorker

- added exposure of IThreader to sample sdk

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401096
This commit is contained in:
David Anderson
2007-07-12 16:57:26 +00:00
parent 8a8e6ef594
commit 529933739d
12 changed files with 119 additions and 17 deletions
+36 -2
View File
@@ -27,7 +27,7 @@
#include <IShareSys.h>
#define SMINTERFACE_THREADER_NAME "IThreader"
#define SMINTERFACE_THREADER_VERSION 1
#define SMINTERFACE_THREADER_VERSION 2
namespace SourceMod
{
@@ -351,6 +351,31 @@ namespace SourceMod
virtual WorkerState GetStatus(unsigned int *numThreads) =0;
};
/**
* @brief Describes thread worker callbacks.
*/
class IThreadWorkerCallbacks
{
public:
/**
* @brief Called when the worker thread is initialized.
*
* @param pWorker Pointer to the worker.
*/
virtual void OnWorkerStart(IThreadWorker *pWorker)
{
}
/**
* @brief Called when the worker thread is cleaning up.
*
* @param pWorker Pointer to the worker.
*/
virtual void OnWorkerStop(IThreadWorker *pWorker)
{
}
};
/**
* @brief Describes a threading system
*/
@@ -365,6 +390,14 @@ namespace SourceMod
{
return SMINTERFACE_THREADER_VERSION;
}
virtual bool IsVersionCompatible(unsigned int version)
{
if (version < 2)
{
return false;
}
return SMInterface::IsVersionCompatible(version);
}
public:
/**
* @brief Creates a mutex (mutual exclusion lock).
@@ -390,11 +423,12 @@ namespace SourceMod
/**
* @brief Creates a thread worker.
*
* @param hooks Optional pointer to callback interface.
* @param threaded If true, the worker will be threaded.
* If false, the worker will require manual frame execution.
* @return A new IThreadWorker pointer (must be destroyed).
*/
virtual IThreadWorker *MakeWorker(bool threaded) =0;
virtual IThreadWorker *MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded) =0;
/**
* @brief Destroys an IThreadWorker pointer.
+1
View File
@@ -54,5 +54,6 @@
//#define SMEXT_ENABLE_MEMUTILS
//#define SMEXT_ENABLE_GAMEHELPERS
//#define SMEXT_ENABLE_TIMERSYS
//#define SMEXT_ENABLE_THREADER
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
+6
View File
@@ -60,6 +60,9 @@ ITimerSystem *timersys = NULL;
#if defined SMEXT_ENABLE_ADTFACTORY
IADTFactory *adtfactory = NULL;
#endif
#if defined SMEXT_ENABLE_THREADER
IThreader *threader = NULL;
#endif
/** Exports the main interface */
PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI()
@@ -124,6 +127,9 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error,
#if defined SMEXT_ENABLE_ADTFACTORY
SM_GET_IFACE(ADTFACTORY, adtfactory);
#endif
#if defined SMEXT_ENABLE_THREADER
SM_GET_IFACE(THREADER, threader);
#endif
if (SDK_OnLoad(error, maxlength, late))
{
+6
View File
@@ -54,6 +54,9 @@
#if defined SMEXT_ENABLE_ADTFACTORY
#include <IADTFactory.h>
#endif
#if defined SMEXT_ENABLE_THREADER
#include <IThreader.h>
#endif
#if defined SMEXT_CONF_METAMOD
#include <ISmmPlugin.h>
@@ -231,6 +234,9 @@ extern ITimerSystem *timersys;
#if defined SMEXT_ENABLE_ADTFACTORY
extern IADTFactory *adtfactory;
#endif
#if defined SMEXT_ENABLE_THREADER
extern IThreader *threader;
#endif
#if defined SMEXT_CONF_METAMOD
PLUGIN_GLOBALVARS();