Revision: 2586
http://zoolib.svn.sourceforge.net/zoolib/?rev=2586&view=rev
Author: agreen
Date: 2011-10-24 14:14:21 +0000 (Mon, 24 Oct 2011)
Log Message:
-----------
Name change ZFuture-->ZDelivery.
Modified Paths:
--------------
trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h
Added Paths:
-----------
trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h
trunk/zoolib/source/cxx/zoolib/ZPromise.h
Removed Paths:
-------------
trunk/zoolib/source/cxx/zoolib/ZCallFuture.h
trunk/zoolib/source/cxx/zoolib/ZFuture.h
Added: trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h (rev 0)
+++ trunk/zoolib/source/cxx/zoolib/ZCallByCaller.h 2011-10-24 14:14:21 UTC (rev 2586)
@@ -0,0 +1,54 @@
+/* -------------------------------------------------------------------------------------------------
+Copyright (c) 2011 Andrew Green
+http://www.zoolib.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+and associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES
+OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+------------------------------------------------------------------------------------------------- */
+
+#ifndef __ZCallByCaller__
+#define __ZCallByCaller__ 1
+#include "zconfig.h"
+
+#include "zoolib/ZCaller.h"
+#include "zoolib/ZCallable.h"
+#include "zoolib/ZCallable_Bind.h"
+#include "zoolib/ZCallable_Function.h"
+#include "zoolib/ZPromise.h"
+
+namespace ZooLib {
+
+// =================================================================================================
+#pragma mark -
+#pragma mark * sCallByCaller
+
+template <class T>
+void spCallWithPromise_T
+ (const ZRef<ZPromise<ZQ<T> > >& iPromise, const ZRef<ZCallable<T(void)> >& iCallable)
+ { iPromise->Set(sQCall(iCallable)); }
+
+template <class T>
+ZRef<ZDelivery<ZQ<T> > > sCallByCaller
+ (const ZRef<ZCaller>& iCaller, const ZRef<ZCallable<T(void)> >& iCallable)
+ {
+ ZRef<ZPromise<ZQ<T> > > thePromise = sPromise<ZQ<T> >();
+ if (iCaller)
+ iCaller->Queue(sBindR(sCallable(spCallWithPromise_T<T>), thePromise, iCallable));
+ return thePromise->Get();
+ }
+
+} // namespace ZooLib
+
+#endif // __ZCallByCaller__
Deleted: trunk/zoolib/source/cxx/zoolib/ZCallFuture.h
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZCallFuture.h 2011-10-22 17:55:57 UTC (rev 2585)
+++ trunk/zoolib/source/cxx/zoolib/ZCallFuture.h 2011-10-24 14:14:21 UTC (rev 2586)
@@ -1,54 +0,0 @@
-/* -------------------------------------------------------------------------------------------------
-Copyright (c) 2011 Andrew Green
-http://www.zoolib.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-and associated documentation files (the "Software"), to deal in the Software without restriction,
-including without limitation the rights to use, copy, modify, merge, publish, distribute,
-sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
-is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES
-OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
-OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------------------------------- */
-
-#ifndef __ZCallFuture__
-#define __ZCallFuture__ 1
-#include "zconfig.h"
-
-#include "zoolib/ZCaller.h"
-#include "zoolib/ZCallable.h"
-#include "zoolib/ZCallable_Bind.h"
-#include "zoolib/ZCallable_Function.h"
-#include "zoolib/ZFuture.h"
-
-namespace ZooLib {
-
-// =================================================================================================
-#pragma mark -
-#pragma mark * sCallFuture
-
-template <class T>
-void sCallWithPromise_T
- (const ZRef<ZPromise<ZQ<T> > >& iPromise, const ZRef<ZCallable<T(void)> >& iCallable)
- { iPromise->Set(sQCall(iCallable)); }
-
-template <class T>
-ZRef<ZFuture<ZQ<T> > > sCallFuture
- (const ZRef<ZCaller>& iCaller, const ZRef<ZCallable<T(void)> >& iCallable)
- {
- ZRef<ZPromise<ZQ<T> > > thePromise = sPromise<ZQ<T> >();
- if (iCaller)
- iCaller->Queue(sBindR(sCallable(sCallWithPromise_T<T>), thePromise, iCallable));
- return thePromise->Get();
- }
-
-} // namespace ZooLib
-
-#endif // __ZCallFuture__
Modified: trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h 2011-10-22 17:55:57 UTC (rev 2585)
+++ trunk/zoolib/source/cxx/zoolib/ZCallable_Caller.h 2011-10-24 14:14:21 UTC (rev 2586)
@@ -22,7 +22,7 @@
#define __ZCallable_Caller__ 1
#include "zconfig.h"
-#include "zoolib/ZCallFuture.h"
+#include "zoolib/ZCallByCaller.h"
namespace ZooLib {
namespace ZCallable_Caller {
@@ -52,7 +52,7 @@
// From ZCallable
virtual ZQ<R> QCall()
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
fCallable)->QGet().DGet(null);
}
@@ -81,7 +81,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0))->QGet().DGet(null);
}
@@ -110,7 +110,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0, P1 i1)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1))->QGet().DGet(null);
}
@@ -139,7 +139,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2))->QGet().DGet(null);
}
@@ -168,7 +168,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3))->QGet().DGet(null);
}
@@ -198,7 +198,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4))->QGet().DGet(null);
}
@@ -228,7 +228,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5))->QGet().DGet(null);
}
@@ -258,7 +258,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6))->QGet().DGet(null);
}
@@ -288,7 +288,7 @@
// From ZCallable
virtual ZQ<R> QCall(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7))->QGet().DGet(null);
}
@@ -321,7 +321,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8))->QGet().DGet(null);
}
@@ -354,7 +354,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8, P9 i9)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9))->QGet().DGet(null);
}
@@ -387,7 +387,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8, P9 i9, PA iA)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA))->QGet().DGet(null);
}
@@ -420,7 +420,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8, P9 i9, PA iA, PB iB)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iB))->QGet().DGet(null);
}
@@ -454,7 +454,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8, P9 i9, PA iA, PB iB, PC iC)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7,
i8, i9, iA, iB, iC))->QGet().DGet(null);
}
@@ -489,7 +489,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8, P9 i9, PA iA, PB iB, PC iC, PD iD)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7,
i8, i9, iA, iB, iC, iD))->QGet().DGet(null);
}
@@ -524,7 +524,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8, P9 i9, PA iA, PB iB, PC iC, PD iD, PE iE)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7,
i8, i9, iA, iB, iC, iD, iE))->QGet().DGet(null);
}
@@ -559,7 +559,7 @@
(P0 i0, P1 i1, P2 i2, P3 i3, P4 i4, P5 i5, P6 i6, P7 i7,
P8 i8, P9 i9, PA iA, PB iB, PC iC, PD iD, PE iE, PF iF)
{
- return sCallFuture(fCaller,
+ return sCallByCaller(fCaller,
sBindR(fCallable, i0, i1, i2, i3, i4, i5, i6, i7,
i8, i9, iA, iB, iC, iD, iE, iF))->QGet().DGet(null);
}
Deleted: trunk/zoolib/source/cxx/zoolib/ZFuture.h
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZFuture.h 2011-10-22 17:55:57 UTC (rev 2585)
+++ trunk/zoolib/source/cxx/zoolib/ZFuture.h 2011-10-24 14:14:21 UTC (rev 2586)
@@ -1,229 +0,0 @@
-/* -------------------------------------------------------------------------------------------------
-Copyright (c) 2011 Andrew Green
-http://www.zoolib.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-and associated documentation files (the "Software"), to deal in the Software without restriction,
-including without limitation the rights to use, copy, modify, merge, publish, distribute,
-sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
-is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES
-OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
-OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------------------------------- */
-
-#ifndef __ZFuture__
-#define __ZFuture__ 1
-#include "zconfig.h"
-
-#include "zoolib/ZCountedWithoutFinalize.h"
-#include "zoolib/ZQ.h"
-#include "zoolib/ZRef.h"
-#include "zoolib/ZThread.h"
-
-namespace ZooLib {
-
-template <class T> class ZPromise;
-
-// =================================================================================================
-#pragma mark -
-#pragma mark * ZFuture
-
-template <class T>
-class ZFuture
-: public ZCountedWithoutFinalize
- {
- ZFuture()
- : fPromiseExists(true)
- {}
-
-public:
- virtual ~ZFuture()
- {}
-
- void Wait()
- {
- ZAcqMtx acq(fMtx);
- for (;;)
- {
- if (fVal || not fPromiseExists)
- return;
- fCnd.Wait(fMtx);
- }
- }
-
- bool WaitFor(double iTimeout)
- {
- ZAcqMtx acq(fMtx);
-
- if (fVal || not fPromiseExists)
- return true;
-
- fCnd.WaitFor(fMtx, iTimeout);
-
- if (fVal || not fPromiseExists)
- return true;
-
- return false;
- }
-
- bool WaitUntil(ZTime iDeadline)
- {
- ZAcqMtx acq(fMtx);
-
- if (fVal || not fPromiseExists)
- return true;
-
- fCnd.WaitUntil(fMtx, iDeadline);
-
- if (fVal || not fPromiseExists)
- return true;
-
- return false;
- }
-
- ZQ<T> QGet()
- {
- ZAcqMtx acq(fMtx);
- while (fPromiseExists && not fVal)
- fCnd.Wait(fMtx);
- return fVal;
- }
-
-private:
- friend class ZPromise<T>;
- ZMtx fMtx;
- ZCnd fCnd;
- bool fPromiseExists;
- ZQ<T> fVal;
- };
-
-// =================================================================================================
-#pragma mark -
-#pragma mark * ZPromise
-
-template <class T>
-class ZPromise
-: public ZCountedWithoutFinalize
- {
-public:
- ZPromise()
- : fFuture(new ZFuture<T>)
- {}
-
- virtual ~ZPromise()
- {
- ZAcqMtx acq(fFuture->fMtx);
- fFuture->fPromiseExists = false;
- fFuture->fCnd.Broadcast();
- }
-
- bool IsSet()
- {
- ZAcqMtx acq(fFuture->fMtx);
- return fFuture->fVal;
- }
-
- void Set(const T& iVal)
- {
- ZAcqMtx acq(fFuture->fMtx);
- fFuture->fVal.Set(iVal);
- fFuture->fCnd.Broadcast();
- }
-
- bool SetIfNotSet(const T& iVal)
- {
- ZAcqMtx acq(fFuture->fMtx);
- if (fFuture->fVal)
- return false;
- fFuture->fVal.Set(iVal);
- fFuture->fCnd.Broadcast();
- return true;
- }
-
- ZRef<ZFuture<T> > Get()
- { return fFuture; }
-
-private:
- ZRef<ZFuture<T> > fFuture;
- };
-
-// =================================================================================================
-#pragma mark -
-#pragma mark * ZPromise<void>
-
-template <>
-class ZPromise<void>
-: public ZCountedWithoutFinalize
- {
-public:
- ZPromise()
- : fFuture(new ZFuture<void>)
- {}
-
- virtual ~ZPromise()
- {
- ZAcqMtx acq(fFuture->fMtx);
- fFuture->fPromiseExists = false;
- fFuture->fCnd.Broadcast();
- }
-
- bool IsSet()
- {
- ZAcqMtx acq(fFuture->fMtx);
- return fFuture->fVal;
- }
-
- void Set()
- {
- ZAcqMtx acq(fFuture->fMtx);
- fFuture->fVal.Set();
- fFuture->fCnd.Broadcast();
- }
-
- bool SetIfNotSet()
- {
- ZAcqMtx acq(fFuture->fMtx);
- if (fFuture->fVal)
- return false;
- fFuture->fVal.Set();
- fFuture->fCnd.Broadcast();
- return true;
- }
-
- ZRef<ZFuture<void> > Get()
- { return fFuture; }
-
-private:
- ZRef<ZFuture<void> > fFuture;
- };
-
-// =================================================================================================
-#pragma mark -
-#pragma mark * sPromise
-
-template <class T>
-ZRef<ZPromise<T> > sPromise()
- { return new ZPromise<T>; }
-
-// =================================================================================================
-#pragma mark -
-#pragma mark * sGetClear
-
-template <class T>
-ZRef<ZFuture<T> > sGetClear(ZRef<ZPromise<T> >& ioPromise)
- {
- ZRef<ZFuture<T> > theFuture = ioPromise->Get();
- ioPromise.Clear();
- return theFuture;
- }
-
-} // namespace ZooLib
-
-#endif // __ZFuture__
Added: trunk/zoolib/source/cxx/zoolib/ZPromise.h
===================================================================
--- trunk/zoolib/source/cxx/zoolib/ZPromise.h (rev 0)
+++ trunk/zoolib/source/cxx/zoolib/ZPromise.h 2011-10-24 14:14:21 UTC (rev 2586)
@@ -0,0 +1,229 @@
+/* -------------------------------------------------------------------------------------------------
+Copyright (c) 2011 Andrew Green
+http://www.zoolib.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+and associated documentation files (the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge, publish, distribute,
+sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES
+OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+------------------------------------------------------------------------------------------------- */
+
+#ifndef __ZPromise__
+#define __ZPromise__ 1
+#include "zconfig.h"
+
+#include "zoolib/ZCountedWithoutFinalize.h"
+#include "zoolib/ZQ.h"
+#include "zoolib/ZRef.h"
+#include "zoolib/ZThread.h"
+
+namespace ZooLib {
+
+template <class T> class ZPromise;
+
+// =================================================================================================
+#pragma mark -
+#pragma mark * ZDelivery
+
+template <class T>
+class ZDelivery
+: public ZCountedWithoutFinalize
+ {
+ ZDelivery()
+ : fPromiseExists(true)
+ {}
+
+public:
+ virtual ~ZDelivery()
+ {}
+
+ void Wait()
+ {
+ ZAcqMtx acq(fMtx);
+ for (;;)
+ {
+ if (fVal || not fPromiseExists)
+ return;
+ fCnd.Wait(fMtx);
+ }
+ }
+
+ bool WaitFor(double iTimeout)
+ {
+ ZAcqMtx acq(fMtx);
+
+ if (fVal || not fPromiseExists)
+ return true;
+
+ fCnd.WaitFor(fMtx, iTimeout);
+
+ if (fVal || not fPromiseExists)
+ return true;
+
+ return false;
+ }
+
+ bool WaitUntil(ZTime iDeadline)
+ {
+ ZAcqMtx acq(fMtx);
+
+ if (fVal || not fPromiseExists)
+ return true;
+
+ fCnd.WaitUntil(fMtx, iDeadline);
+
+ if (fVal || not fPromiseExists)
+ return true;
+
+ return false;
+ }
+
+ ZQ<T> QGet()
+ {
+ ZAcqMtx acq(fMtx);
+ while (fPromiseExists && not fVal)
+ fCnd.Wait(fMtx);
+ return fVal;
+ }
+
+private:
+ friend class ZPromise<T>;
+ ZMtx fMtx;
+ ZCnd fCnd;
+ bool fPromiseExists;
+ ZQ<T> fVal;
+ };
+
+// =================================================================================================
+#pragma mark -
+#pragma mark * ZPromise
+
+template <class T>
+class ZPromise
+: public ZCountedWithoutFinalize
+ {
+public:
+ ZPromise()
+ : fDelivery(new ZDelivery<T>)
+ {}
+
+ virtual ~ZPromise()
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ fDelivery->fPromiseExists = false;
+ fDelivery->fCnd.Broadcast();
+ }
+
+ bool IsSet()
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ return fDelivery->fVal;
+ }
+
+ void Set(const T& iVal)
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ fDelivery->fVal.Set(iVal);
+ fDelivery->fCnd.Broadcast();
+ }
+
+ bool SetIfNotSet(const T& iVal)
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ if (fDelivery->fVal)
+ return false;
+ fDelivery->fVal.Set(iVal);
+ fDelivery->fCnd.Broadcast();
+ return true;
+ }
+
+ ZRef<ZDelivery<T> > Get()
+ { return fDelivery; }
+
+private:
+ ZRef<ZDelivery<T> > fDelivery;
+ };
+
+// =================================================================================================
+#pragma mark -
+#pragma mark * ZPromise<void>
+
+template <>
+class ZPromise<void>
+: public ZCountedWithoutFinalize
+ {
+public:
+ ZPromise()
+ : fDelivery(new ZDelivery<void>)
+ {}
+
+ virtual ~ZPromise()
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ fDelivery->fPromiseExists = false;
+ fDelivery->fCnd.Broadcast();
+ }
+
+ bool IsSet()
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ return fDelivery->fVal;
+ }
+
+ void Set()
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ fDelivery->fVal.Set();
+ fDelivery->fCnd.Broadcast();
+ }
+
+ bool SetIfNotSet()
+ {
+ ZAcqMtx acq(fDelivery->fMtx);
+ if (fDelivery->fVal)
+ return false;
+ fDelivery->fVal.Set();
+ fDelivery->fCnd.Broadcast();
+ return true;
+ }
+
+ ZRef<ZDelivery<void> > Get()
+ { return fDelivery; }
+
+private:
+ ZRef<ZDelivery<void> > fDelivery;
+ };
+
+// =================================================================================================
+#pragma mark -
+#pragma mark * sPromise
+
+template <class T>
+ZRef<ZPromise<T> > sPromise()
+ { return new ZPromise<T>; }
+
+// =================================================================================================
+#pragma mark -
+#pragma mark * sGetClear
+
+template <class T>
+ZRef<ZDelivery<T> > sGetClear(ZRef<ZPromise<T> >& ioPromise)
+ {
+ ZRef<ZDelivery<T> > theDelivery = ioPromise->Get();
+ ioPromise.Clear();
+ return theDelivery;
+ }
+
+} // namespace ZooLib
+
+#endif // __ZPromise__
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|