summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/Promise.cpp
diff options
context:
space:
mode:
authorTycho Bickerstaff <work.tycho@gmail.com>2013-12-31 17:13:13 +0100
committerTycho Bickerstaff <work.tycho@gmail.com>2013-12-31 17:13:13 +0100
commit098ed91a48df9fef58590b22fe34225ed1f44cfa (patch)
tree0bd8fff5833d6b6636195ee73faaced13ddcba90 /src/OSSupport/Promise.cpp
parentclean up code for patching (diff)
downloadcuberite-098ed91a48df9fef58590b22fe34225ed1f44cfa.tar
cuberite-098ed91a48df9fef58590b22fe34225ed1f44cfa.tar.gz
cuberite-098ed91a48df9fef58590b22fe34225ed1f44cfa.tar.bz2
cuberite-098ed91a48df9fef58590b22fe34225ed1f44cfa.tar.lz
cuberite-098ed91a48df9fef58590b22fe34225ed1f44cfa.tar.xz
cuberite-098ed91a48df9fef58590b22fe34225ed1f44cfa.tar.zst
cuberite-098ed91a48df9fef58590b22fe34225ed1f44cfa.zip
Diffstat (limited to 'src/OSSupport/Promise.cpp')
-rw-r--r--src/OSSupport/Promise.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/OSSupport/Promise.cpp b/src/OSSupport/Promise.cpp
new file mode 100644
index 000000000..b31869334
--- /dev/null
+++ b/src/OSSupport/Promise.cpp
@@ -0,0 +1,54 @@
+
+#include "Globals.h"
+
+#include "Promise.h"
+
+cPromise * cPromise::WaitFor(cPromise * a_Promise)
+{
+ return new cCombinedPromise(this, a_Promise);
+}
+
+cPromise * cPromise::CancelOn(volatile bool& cancelation)
+{
+ return new cCancelablePromise(this, cancelation);
+}
+
+void cPromise::Wait()
+{
+ while(!IsCompleted()){}; //busywait best we can do until waitany
+}
+
+
+cCombinedPromise::cCombinedPromise(cPromise* a_left, cPromise* a_right) :
+ cPromise(),
+ m_left(a_left),
+ m_right(a_right)
+{
+}
+
+cCombinedPromise::~cCombinedPromise()
+{
+}
+
+bool cCombinedPromise::IsCompleted()
+{
+ return m_left->IsCompleted() || m_right->IsCompleted();
+}
+
+cCancelablePromise::cCancelablePromise(cPromise* a_wrapped, volatile bool& a_cancel) :
+ cPromise(),
+ m_cancel(a_cancel),
+ m_wrapped(a_wrapped)
+{
+}
+
+cCancelablePromise::~cCancelablePromise ()
+{
+}
+
+bool cCancelablePromise::IsCompleted()
+{
+ return m_cancel || m_wrapped->IsCompleted();
+}
+
+