aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/async.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-22 04:50:18 +0000
committerlloyd <[email protected]>2009-12-22 04:50:18 +0000
commitc85c79ac51b5829258dae7e51bb472b740da9574 (patch)
treed02818ecdf25c028ead796c2a06bc10ac596924f /src/utils/async.h
parentc2c896ee870285b836f80b30a042941b03ddd440 (diff)
parent93e8fd697d009dfef3b994a77936cbf88d2d2ba3 (diff)
propagate from branch 'net.randombit.botan' (head 5525439539abc808b7b8588380a362303cf3c599)
to branch 'net.randombit.botan.c++0x' (head 6749468bfbdeff4636b7a15de412a6c89f1aea87)
Diffstat (limited to 'src/utils/async.h')
-rw-r--r--src/utils/async.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utils/async.h b/src/utils/async.h
new file mode 100644
index 000000000..85702c114
--- /dev/null
+++ b/src/utils/async.h
@@ -0,0 +1,33 @@
+/**
+* Standin for C++0x's std::async
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_ASYNC_H__
+#define BOTAN_ASYNC_H__
+
+#include <future>
+#include <thread>
+
+namespace Botan {
+
+/**
+* A simple version of std::async (as it is not in GCC 4.5)
+* Will be removed once GCC supports it natively
+*/
+template<typename F>
+auto std_async(F f) -> std::unique_future<decltype(f())>
+ {
+ typedef decltype(f()) result_type;
+ std::packaged_task<result_type ()> task(std::move(f));
+ std::unique_future<result_type> future = task.get_future();
+ std::thread thread(std::move(task));
+ thread.detach();
+ return future;
+ }
+
+}
+
+#endif