Merge pull request #180 from vibe-d/fix_yieldlock_destruction
Make sure that an uninitialized YieldLock does not decrement the lock counter merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
This commit is contained in:
commit
b976519057
|
@ -1202,11 +1202,11 @@ auto yieldLock()
|
||||||
@safe nothrow {
|
@safe nothrow {
|
||||||
static struct YieldLock {
|
static struct YieldLock {
|
||||||
@safe nothrow:
|
@safe nothrow:
|
||||||
|
private bool m_initialized;
|
||||||
|
|
||||||
private this(bool) { inc(); }
|
private this(bool) { m_initialized = true; inc(); }
|
||||||
@disable this();
|
|
||||||
@disable this(this);
|
@disable this(this);
|
||||||
~this() { dec(); }
|
~this() { if (m_initialized) dec(); }
|
||||||
|
|
||||||
private void inc()
|
private void inc()
|
||||||
{
|
{
|
||||||
|
@ -1215,6 +1215,7 @@ auto yieldLock()
|
||||||
|
|
||||||
private void dec()
|
private void dec()
|
||||||
{
|
{
|
||||||
|
assert(TaskFiber.getThis().m_yieldLockCount > 0);
|
||||||
TaskFiber.getThis().m_yieldLockCount--;
|
TaskFiber.getThis().m_yieldLockCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1235,6 +1236,12 @@ unittest {
|
||||||
assert(tf.m_yieldLockCount == 1);
|
assert(tf.m_yieldLockCount == 1);
|
||||||
}
|
}
|
||||||
assert(tf.m_yieldLockCount == 0);
|
assert(tf.m_yieldLockCount == 0);
|
||||||
|
|
||||||
|
{
|
||||||
|
typeof(yieldLock()) l;
|
||||||
|
assert(tf.m_yieldLockCount == 0);
|
||||||
|
}
|
||||||
|
assert(tf.m_yieldLockCount == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue