diff options
| author | Alexander Gavrilov | 2012-08-18 11:52:38 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-08-18 11:52:38 +0400 |
| commit | 24cc8b5c7add7e18b6bd42eea743a9e9d562a336 (patch) | |
| tree | cc039bcc2e032ac2a8639929693caed1b66e7638 /library/include | |
| parent | 01ba2a31fc2dd7597ab6e2db3f1496b123e10720 (diff) | |
| download | dfhack-24cc8b5c7add7e18b6bd42eea743a9e9d562a336.tar.gz dfhack-24cc8b5c7add7e18b6bd42eea743a9e9d562a336.tar.bz2 dfhack-24cc8b5c7add7e18b6bd42eea743a9e9d562a336.tar.xz | |
Expose an API to claim the suspend lock from the Core.
Previously it was hard-coded in Core::Update, but interposed
vmethods may need this feature too.
Diffstat (limited to 'library/include')
| -rw-r--r-- | library/include/Core.h | 21 | ||||
| -rw-r--r-- | library/include/VTableInterpose.h | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/library/include/Core.h b/library/include/Core.h index d25beef5..e1f1cf3f 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -174,6 +174,10 @@ namespace DFHack struct Private; Private *d; + friend class CoreSuspendClaimer; + int ClaimSuspend(bool force_base); + void DisclaimSuspend(int level); + bool Init(); int Update (void); int TileUpdate (void); @@ -181,6 +185,7 @@ namespace DFHack int DFH_SDL_Event(SDL::Event* event); bool ncurses_wgetch(int in, int & out); + void doUpdate(color_ostream &out, bool first_update); void onUpdate(color_ostream &out); void onStateChange(color_ostream &out, state_change_event event); @@ -249,4 +254,20 @@ namespace DFHack CoreSuspender(Core *core) : core(core) { core->Suspend(); } ~CoreSuspender() { core->Resume(); } }; + + /** Claims the current thread already has the suspend lock. + * Strictly for use in callbacks from DF. + */ + class CoreSuspendClaimer { + Core *core; + int level; + public: + CoreSuspendClaimer(bool base = false) : core(&Core::getInstance()) { + level = core->ClaimSuspend(base); + } + CoreSuspendClaimer(Core *core, bool base = false) : core(core) { + level = core->ClaimSuspend(base); + } + ~CoreSuspendClaimer() { core->DisclaimSuspend(level); } + }; } diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h index 5eaeaed8..bb7a37ce 100644 --- a/library/include/VTableInterpose.h +++ b/library/include/VTableInterpose.h @@ -95,6 +95,9 @@ namespace DFHack typedef df::someclass interpose_base; DEFINE_VMETHOD_INTERPOSE(void, foo, (int arg)) { + // If needed by the code, claim the suspend lock. + // DO NOT USE THE USUAL CoreSuspender, OR IT WILL DEADLOCK! + // CoreSuspendClaimer suspend; ... INTERPOSE_NEXT(foo)(arg) // call the original ... |
