From 452fa411c2ae1c5dde49ae4fdece41ebffdf1bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 14 Jan 2019 00:05:10 +0100 Subject: [PATCH] Avoid overload conflict when using TaskMutex together with InterruptibleTaskCondition. --- source/vibe/core/sync.d | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/vibe/core/sync.d b/source/vibe/core/sync.d index 2710ae0..7ae378d 100644 --- a/source/vibe/core/sync.d +++ b/source/vibe/core/sync.d @@ -699,8 +699,14 @@ final class InterruptibleTaskCondition { private TaskConditionImpl!(true, Lockable) m_impl; - this(core.sync.mutex.Mutex mtx) { m_impl.setup(mtx); } - this(Lockable mtx) { m_impl.setup(mtx); } + this(M)(M mutex) + if (is(M : Mutex) || is (M : Lockable)) + { + static if (is(M : Lockable)) + m_impl.setup(mutex); + else + m_impl.setupForMutex(mutex); + } @property Lockable mutex() { return m_impl.mutex; } void wait() { m_impl.wait(); } @@ -709,6 +715,12 @@ final class InterruptibleTaskCondition { void notifyAll() { m_impl.notifyAll(); } } +unittest { + new InterruptibleTaskCondition(new Mutex); + new InterruptibleTaskCondition(new TaskMutex); + new InterruptibleTaskCondition(new InterruptibleTaskMutex); +} + /** A manually triggered single threaded cross-task event. @@ -1584,7 +1596,7 @@ private struct TaskConditionImpl(bool INTERRUPTIBLE, LOCKABLE) { @trusted bool tryLock() { return m_mutex.tryLock(); } } - void setup(core.sync.mutex.Mutex mtx) + void setupForMutex(core.sync.mutex.Mutex mtx) { setup(new MutexWrapper(mtx)); }