Made thread worker processing limits configurable at runtime (bug 5326, r=psychonic).
This commit is contained in:
parent
e77ad244ad
commit
439986e3fe
@ -124,11 +124,6 @@ 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)
|
||||
@ -140,7 +135,7 @@ WorkerState BaseWorker::GetStatus(unsigned int *threads)
|
||||
unsigned int BaseWorker::RunFrame()
|
||||
{
|
||||
unsigned int done = 0;
|
||||
unsigned int max = GetMaxThreadsPerFrame();
|
||||
unsigned int max = m_perFrame;
|
||||
SWThreadHandle *swt = NULL;
|
||||
IThread *pThread = NULL;
|
||||
|
||||
|
@ -84,6 +84,8 @@ public: //IWorker
|
||||
virtual unsigned int Flush(bool flush_cancel);
|
||||
//returns status and number of threads in queue
|
||||
virtual WorkerState GetStatus(unsigned int *numThreads);
|
||||
virtual void SetMaxThreadsPerFrame(unsigned int threads);
|
||||
virtual void SetThinkTimePerFrame(unsigned int thinktime) {}
|
||||
public: //IThreadCreator
|
||||
virtual void MakeThread(IThread *pThread);
|
||||
virtual IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags);
|
||||
@ -92,8 +94,6 @@ public: //IThreadCreator
|
||||
public: //BaseWorker
|
||||
virtual void AddThreadToQueue(SWThreadHandle *pHandle);
|
||||
virtual SWThreadHandle *PopThreadFromQueue();
|
||||
virtual void SetMaxThreadsPerFrame(unsigned int threads);
|
||||
virtual unsigned int GetMaxThreadsPerFrame();
|
||||
protected:
|
||||
SourceHook::List<SWThreadHandle *> m_ThreadQueue;
|
||||
unsigned int m_perFrame;
|
||||
|
@ -209,6 +209,11 @@ WorkerState ThreadWorker::GetStatus(unsigned int *threads)
|
||||
return state;
|
||||
}
|
||||
|
||||
void ThreadWorker::SetThinkTimePerFrame(unsigned int thinktime)
|
||||
{
|
||||
m_think_time = thinktime;
|
||||
}
|
||||
|
||||
bool ThreadWorker::Start()
|
||||
{
|
||||
if (m_state == Worker_Invalid)
|
||||
|
@ -53,6 +53,8 @@ public: //IWorker
|
||||
virtual bool Stop(bool flush_cancel);
|
||||
//returns status and number of threads in queue
|
||||
virtual WorkerState GetStatus(unsigned int *numThreads);
|
||||
//virtual void SetMaxThreadsPerFrame(unsigned int threads);
|
||||
virtual void SetThinkTimePerFrame(unsigned int thinktime);
|
||||
public: //BaseWorker
|
||||
virtual void AddThreadToQueue(SWThreadHandle *pHandle);
|
||||
virtual SWThreadHandle *PopThreadFromQueue();
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <IShareSys.h>
|
||||
|
||||
#define SMINTERFACE_THREADER_NAME "IThreader"
|
||||
#define SMINTERFACE_THREADER_VERSION 2
|
||||
#define SMINTERFACE_THREADER_VERSION 3
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
@ -362,6 +362,23 @@ namespace SourceMod
|
||||
* @return State of the worker.
|
||||
*/
|
||||
virtual WorkerState GetStatus(unsigned int *numThreads) =0;
|
||||
|
||||
/**
|
||||
* @brief Sets the number of threads to run per frame.
|
||||
* Default value is 1 thread per frame.
|
||||
*
|
||||
* @param threads Number of threads to run per frame.
|
||||
*/
|
||||
virtual void SetMaxThreadsPerFrame(unsigned int threads) =0;
|
||||
|
||||
/**
|
||||
* @brief For threaded workers, the think time of a frame.
|
||||
* Has no effect for non-threaded workers.
|
||||
* Default value is 50ms.
|
||||
*
|
||||
* @param thinktime Number of ms to sleep between frame execution.
|
||||
*/
|
||||
virtual void SetThinkTimePerFrame(unsigned int thinktime) =0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user