diff --git a/src/c_wrapper/async.cpp b/src/c_wrapper/async.cpp index abe9f9f9d3ced510b868a464ae1030b06dc7eb4a..69d76a16a5c8053add841367e2f88c24f019773e 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 321439258e22219bacefc70c60285baa06f83787..43fb60f59a7ef875375a4dd199e7cebdf31b8bef 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); }