Merge branch 'rm-watchdog-singleton'
This commit is contained in:
commit
50d7d7eedb
@ -15,6 +15,7 @@
|
|||||||
#include "watchdog_timer.h"
|
#include "watchdog_timer.h"
|
||||||
#include "debug-trace.h"
|
#include "debug-trace.h"
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
|
#include "watchdog_timer.h"
|
||||||
|
|
||||||
using namespace sp;
|
using namespace sp;
|
||||||
using namespace SourcePawn;
|
using namespace SourcePawn;
|
||||||
@ -29,6 +30,10 @@ Environment::Environment()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Environment::~Environment()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Environment *
|
Environment *
|
||||||
Environment::New()
|
Environment::New()
|
||||||
{
|
{
|
||||||
@ -57,6 +62,7 @@ Environment::Initialize()
|
|||||||
{
|
{
|
||||||
api_v1_ = new SourcePawnEngine();
|
api_v1_ = new SourcePawnEngine();
|
||||||
api_v2_ = new SourcePawnEngine2();
|
api_v2_ = new SourcePawnEngine2();
|
||||||
|
watchdog_timer_ = new WatchdogTimer();
|
||||||
|
|
||||||
if (!g_Jit.InitializeJIT())
|
if (!g_Jit.InitializeJIT())
|
||||||
return false;
|
return false;
|
||||||
@ -67,7 +73,7 @@ Environment::Initialize()
|
|||||||
void
|
void
|
||||||
Environment::Shutdown()
|
Environment::Shutdown()
|
||||||
{
|
{
|
||||||
g_WatchdogTimer.Shutdown();
|
watchdog_timer_->Shutdown();
|
||||||
g_Jit.ShutdownJIT();
|
g_Jit.ShutdownJIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +92,7 @@ Environment::DisableProfiling()
|
|||||||
bool
|
bool
|
||||||
Environment::InstallWatchdogTimer(int timeout_ms)
|
Environment::InstallWatchdogTimer(int timeout_ms)
|
||||||
{
|
{
|
||||||
return g_WatchdogTimer.Initialize(timeout_ms);
|
return watchdog_timer_->Initialize(timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
ISourcePawnEngine *
|
ISourcePawnEngine *
|
||||||
|
@ -22,6 +22,8 @@ namespace sp {
|
|||||||
|
|
||||||
using namespace SourcePawn;
|
using namespace SourcePawn;
|
||||||
|
|
||||||
|
class WatchdogTimer;
|
||||||
|
|
||||||
// An Environment encapsulates everything that's needed to load and run
|
// An Environment encapsulates everything that's needed to load and run
|
||||||
// instances of plugins on a single thread. There can be at most one
|
// instances of plugins on a single thread. There can be at most one
|
||||||
// environment per thread.
|
// environment per thread.
|
||||||
@ -32,6 +34,7 @@ class Environment : public ISourcePawnEnvironment
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Environment();
|
Environment();
|
||||||
|
~Environment();
|
||||||
|
|
||||||
static Environment *New();
|
static Environment *New();
|
||||||
|
|
||||||
@ -77,12 +80,17 @@ class Environment : public ISourcePawnEnvironment
|
|||||||
return debugger_;
|
return debugger_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WatchdogTimer *watchdog() const {
|
||||||
|
return watchdog_timer_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ke::AutoPtr<ISourcePawnEngine> api_v1_;
|
ke::AutoPtr<ISourcePawnEngine> api_v1_;
|
||||||
ke::AutoPtr<ISourcePawnEngine2> api_v2_;
|
ke::AutoPtr<ISourcePawnEngine2> api_v2_;
|
||||||
|
ke::AutoPtr<WatchdogTimer> watchdog_timer_;
|
||||||
|
|
||||||
IDebugListener *debugger_;
|
IDebugListener *debugger_;
|
||||||
IProfilingTool *profiler_;
|
IProfilingTool *profiler_;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
#include "watchdog_timer.h"
|
#include "watchdog_timer.h"
|
||||||
|
#include "environment.h"
|
||||||
|
|
||||||
#define STACK_MARGIN 64
|
#define STACK_MARGIN 64
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ JumpTarget(const sp_plugin_t *plugin, sp_context_t *ctx, cell_t *cip, bool cond)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cell_t *next = reinterpret_cast<cell_t *>(plugin->pcode + target);
|
cell_t *next = reinterpret_cast<cell_t *>(plugin->pcode + target);
|
||||||
if (next < cip && !g_WatchdogTimer.HandleInterrupt()) {
|
if (next < cip && !Environment::get()->watchdog()->HandleInterrupt()) {
|
||||||
ctx->err = SP_ERROR_TIMEOUT;
|
ctx->err = SP_ERROR_TIMEOUT;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -529,7 +529,7 @@ BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsigned
|
|||||||
|
|
||||||
EnterProfileScope profileScope("SourcePawn", "EnterJIT");
|
EnterProfileScope profileScope("SourcePawn", "EnterJIT");
|
||||||
|
|
||||||
if (!g_WatchdogTimer.HandleInterrupt())
|
if (!Environment::get()->watchdog()->HandleInterrupt())
|
||||||
return SP_ERROR_TIMEOUT;
|
return SP_ERROR_TIMEOUT;
|
||||||
|
|
||||||
funcid_t fnid = function->GetFunctionID();
|
funcid_t fnid = function->GetFunctionID();
|
||||||
@ -631,7 +631,7 @@ BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ir == SP_ERROR_TIMEOUT)
|
if (ir == SP_ERROR_TIMEOUT)
|
||||||
g_WatchdogTimer.NotifyTimeoutReceived();
|
Environment::get()->watchdog()->NotifyTimeoutReceived();
|
||||||
|
|
||||||
if (ir != SP_ERROR_NONE)
|
if (ir != SP_ERROR_NONE)
|
||||||
Environment::get()->ReportError(m_pRuntime, ir, m_MsgCache, save_rp);
|
Environment::get()->ReportError(m_pRuntime, ir, m_MsgCache, save_rp);
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
#include "x86/jit_x86.h"
|
#include "x86/jit_x86.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
WatchdogTimer g_WatchdogTimer;
|
|
||||||
|
|
||||||
WatchdogTimer::WatchdogTimer()
|
WatchdogTimer::WatchdogTimer()
|
||||||
: terminate_(false),
|
: terminate_(false),
|
||||||
mainthread_(ke::GetCurrentThreadId()),
|
mainthread_(ke::GetCurrentThreadId()),
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <am-thread-utils.h>
|
#include <am-thread-utils.h>
|
||||||
|
|
||||||
|
namespace sp {
|
||||||
|
|
||||||
typedef bool (*WatchdogCallback)();
|
typedef bool (*WatchdogCallback)();
|
||||||
|
|
||||||
class WatchdogTimer : public ke::IRunnable
|
class WatchdogTimer : public ke::IRunnable
|
||||||
@ -56,6 +58,6 @@ class WatchdogTimer : public ke::IRunnable
|
|||||||
bool timedout_;
|
bool timedout_;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern WatchdogTimer g_WatchdogTimer;
|
} // namespace sp
|
||||||
|
|
||||||
#endif // _include_sourcepawn_watchdog_timer_posix_h_
|
#endif // _include_sourcepawn_watchdog_timer_posix_h_
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "../sp_vm_basecontext.h"
|
#include "../sp_vm_basecontext.h"
|
||||||
#include "watchdog_timer.h"
|
#include "watchdog_timer.h"
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
#include "environment.h"
|
||||||
|
|
||||||
using namespace sp;
|
using namespace sp;
|
||||||
using namespace Knight;
|
using namespace Knight;
|
||||||
@ -274,7 +275,7 @@ CompileFromThunk(PluginRuntime *runtime, cell_t pcode_offs, void **addrp, char *
|
|||||||
// If the watchdog timer has declared a timeout, we must process it now,
|
// If the watchdog timer has declared a timeout, we must process it now,
|
||||||
// and possibly refuse to compile, since otherwise we will compile a
|
// and possibly refuse to compile, since otherwise we will compile a
|
||||||
// function that is not patched for timeouts.
|
// function that is not patched for timeouts.
|
||||||
if (!g_WatchdogTimer.HandleInterrupt())
|
if (!Environment::get()->watchdog()->HandleInterrupt())
|
||||||
return SP_ERROR_TIMEOUT;
|
return SP_ERROR_TIMEOUT;
|
||||||
|
|
||||||
CompiledFunction *fn = runtime->GetJittedFunctionByOffset(pcode_offs);
|
CompiledFunction *fn = runtime->GetJittedFunctionByOffset(pcode_offs);
|
||||||
|
Loading…
Reference in New Issue
Block a user