From f4d33826172cd257ac63f422011a9812cdb3248e Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 16 Mar 2017 01:16:03 +0100 Subject: [PATCH] allow custom condition variable types in channels --- ostd/channel.hh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ostd/channel.hh b/ostd/channel.hh index 5bb24b0..3e0f383 100644 --- a/ostd/channel.hh +++ b/ostd/channel.hh @@ -17,8 +17,20 @@ struct channel_error: std::logic_error { using std::logic_error::logic_error; }; -template +template struct channel { + using condition_variable_type = C; + + /* default ctor works for default C */ + channel() {} + + /* constructing using a function object, keep in mind that condvars are + * not copy or move constructible, so the func has to work in a way that + * elides copying and moving (by directly returning the type ctor call) + */ + template + channel(F func): p_cond(func()) {} + void put(T const &val) { put_impl(val); } @@ -73,7 +85,7 @@ private: } std::list p_messages; - std::condition_variable p_cond; + C p_cond; mutable std::mutex p_lock; bool p_closed = false; };