summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libadhocutil/runtimeContext.cpp16
-rw-r--r--libadhocutil/runtimeContext.h2
-rw-r--r--libadhocutil/unittests/testContext.cpp3
3 files changed, 17 insertions, 4 deletions
diff --git a/libadhocutil/runtimeContext.cpp b/libadhocutil/runtimeContext.cpp
index cb938d4..4cb5a17 100644
--- a/libadhocutil/runtimeContext.cpp
+++ b/libadhocutil/runtimeContext.cpp
@@ -2,6 +2,7 @@
#include <stdexcept>
RuntimeContext::RuntimeContext(size_t stacksize) :
+ completed(false),
swapped(false)
{
stack = malloc(stacksize);
@@ -26,17 +27,26 @@ RuntimeContext::swapContext()
swapcontext(&ctxInitial, &ctxCallback);
}
else {
- if (stack) {
+ if (!completed) {
swapcontext(&ctxCallback, &ctxInitial);
+ if (completed) {
+ free(stack);
+ stack = nullptr;
+ }
}
}
}
+bool
+RuntimeContext::hasCompleted() const
+{
+ return completed;
+}
+
void
RuntimeContext::callbackWrapper(RuntimeContext * rc)
{
rc->callback();
- free(rc->stack);
- rc->stack = nullptr;
+ rc->completed = true;
}
diff --git a/libadhocutil/runtimeContext.h b/libadhocutil/runtimeContext.h
index aa424d4..b7ce0a3 100644
--- a/libadhocutil/runtimeContext.h
+++ b/libadhocutil/runtimeContext.h
@@ -11,6 +11,7 @@ class DLL_PUBLIC RuntimeContext {
virtual ~RuntimeContext();
void swapContext();
+ bool hasCompleted() const;
protected:
DLL_PRIVATE virtual void callback() = 0;
@@ -21,6 +22,7 @@ class DLL_PUBLIC RuntimeContext {
void * stack;
ucontext_t ctxInitial;
ucontext_t ctxCallback;
+ bool completed;
bool swapped;
};
diff --git a/libadhocutil/unittests/testContext.cpp b/libadhocutil/unittests/testContext.cpp
index 727425e..de76493 100644
--- a/libadhocutil/unittests/testContext.cpp
+++ b/libadhocutil/unittests/testContext.cpp
@@ -3,7 +3,7 @@
#include "runtimeContext.h"
-class TestRuntimeContext : RuntimeContext {
+class TestRuntimeContext : public RuntimeContext {
public:
void run()
{
@@ -32,5 +32,6 @@ BOOST_AUTO_TEST_CASE ( basic )
TestRuntimeContext trc;
trc.run();
BOOST_REQUIRE_EQUAL("aebfcd", trc.log);
+ BOOST_REQUIRE(trc.hasCompleted());
}