diff options
author | Max Horn | 2010-10-30 00:33:54 +0000 |
---|---|---|
committer | Max Horn | 2010-10-30 00:33:54 +0000 |
commit | ac94cf274290911fc3ee5395202b30f161601a62 (patch) | |
tree | fb0d699467711aefdc8a0f2de927b06ea9c16818 /engines/tinsel/coroutine.h | |
parent | afb5986c9eaf172d2a00530012702f7054e95521 (diff) | |
download | scummvm-rg350-ac94cf274290911fc3ee5395202b30f161601a62.tar.gz scummvm-rg350-ac94cf274290911fc3ee5395202b30f161601a62.tar.bz2 scummvm-rg350-ac94cf274290911fc3ee5395202b30f161601a62.zip |
TINSEL: Fix subtle leak in coroutine code, some minor tweaks
* Fix a bug which caused coroutines invoked with nullContext to
leak their state.
Sadly, nullContext is underdocumented, yet very delicate and
full of subtleties... ./
* Move nullContext decl from sched.cpp to coroutine.cpp
* Enhance a few doxygen comments
svn-id: r53934
Diffstat (limited to 'engines/tinsel/coroutine.h')
-rw-r--r-- | engines/tinsel/coroutine.h | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/engines/tinsel/coroutine.h b/engines/tinsel/coroutine.h index 5a8084b7e3..c8b220b212 100644 --- a/engines/tinsel/coroutine.h +++ b/engines/tinsel/coroutine.h @@ -109,9 +109,7 @@ public: }; -#define CORO_PARAM CoroContext &coroParam - -#define CORO_SUBCTX coroParam->_subctx +#define CORO_PARAM CoroContext &coroParam /** @@ -159,7 +157,10 @@ public: * @see CORO_END_CODE */ #define CORO_END_CODE \ - if (&coroParam == &nullContext) nullContext = NULL; \ + if (&coroParam == &nullContext) { \ + delete nullContext; \ + nullContext = NULL; \ + } \ } /** @@ -181,11 +182,28 @@ public: #define CORO_KILL_SELF() \ do { if (&coroParam != &nullContext) { coroParam->_sleep = -1; } return; } while (0) + +/** + * This macro is to be used in conjunction with CORO_INVOKE_ARGS and + * similar macros for calling coroutines-enabled subroutines. + */ +#define CORO_SUBCTX coroParam->_subctx + /** * Invoke another coroutine. * * What makes this tricky is that the coroutine we called my yield/sleep, * and we need to deal with this adequately. + * + * @param subCoro name of the coroutine-enabled function to invoke + * @param ARGS list of arguments to pass to subCoro + * + * @note ARGS must be surrounded by parentheses, and the first argument + * in this list must always be CORO_SUBCTX. For example, the + * regular function call + * myFunc(a, b); + * becomes the following: + * CORO_INVOKE_ARGS(myFunc, (CORO_SUBCTX, a, b)); */ #define CORO_INVOKE_ARGS(subCoro, ARGS) \ do {\ |