From 06f0f807385459beca6c10d50e1051108a121fbb Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Thu, 19 Jun 2014 00:19:47 +0800 Subject: [PATCH] async --- src/c_wrapper/async.cpp | 10 ++++++---- src/c_wrapper/async.h | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/c_wrapper/async.cpp b/src/c_wrapper/async.cpp index abe9f9f9..69d76a16 100644 --- a/src/c_wrapper/async.cpp +++ b/src/c_wrapper/async.cpp @@ -1,4 +1,5 @@ #include "async.h" +#include "function.h" #include #include @@ -14,7 +15,7 @@ private: std::mutex m_mutex; std::condition_variable m_cond; public: - T + PYOPENCL_INLINE T pop() { std::unique_lock mlock(m_mutex); @@ -25,10 +26,11 @@ public: m_queue.pop(); return item; } - void + PYOPENCL_INLINE void push(const T &item) { { + // Sub scope for the lock std::unique_lock mlock(m_mutex); m_queue.push(item); } @@ -58,12 +60,12 @@ private: t.detach(); } public: - void + PYOPENCL_INLINE void ensure_thread() { std::call_once(m_flag, &AsyncCaller::start_thread, this); } - void + PYOPENCL_INLINE void push(const std::function &func) { ensure_thread(); diff --git a/src/c_wrapper/async.h b/src/c_wrapper/async.h index 32143925..43fb60f5 100644 --- a/src/c_wrapper/async.h +++ b/src/c_wrapper/async.h @@ -5,7 +5,9 @@ namespace pyopencl { +// Start the helper thread void init_async(); +// Call @func in the helper thread void call_async(const std::function &func); } -- GitLab