Make sure that an uninitialized YieldLock does not decrement the lock counter.
Uninitialized YieldLock values can happen in various ways, dispite the default constructor being disabled. If any such value got destroyed, it would lead to a negative lock count. Since this is handled properly now, the default constructor is also enabled in this commit.
This commit is contained in:
parent
24a83434e4
commit
aae2c28ef6
1 changed files with 11 additions and 4 deletions
|
@ -1201,12 +1201,12 @@ private struct TimerCallbackHandler(CALLABLE) {
|
|||
auto yieldLock()
|
||||
@safe nothrow {
|
||||
static struct YieldLock {
|
||||
@safe nothrow:
|
||||
@safe nothrow:
|
||||
private bool m_initialized;
|
||||
|
||||
private this(bool) { inc(); }
|
||||
@disable this();
|
||||
private this(bool) { m_initialized = true; inc(); }
|
||||
@disable this(this);
|
||||
~this() { dec(); }
|
||||
~this() { if (m_initialized) dec(); }
|
||||
|
||||
private void inc()
|
||||
{
|
||||
|
@ -1215,6 +1215,7 @@ auto yieldLock()
|
|||
|
||||
private void dec()
|
||||
{
|
||||
assert(TaskFiber.getThis().m_yieldLockCount > 0);
|
||||
TaskFiber.getThis().m_yieldLockCount--;
|
||||
}
|
||||
}
|
||||
|
@ -1235,6 +1236,12 @@ unittest {
|
|||
assert(tf.m_yieldLockCount == 1);
|
||||
}
|
||||
assert(tf.m_yieldLockCount == 0);
|
||||
|
||||
{
|
||||
typeof(yieldLock()) l;
|
||||
assert(tf.m_yieldLockCount == 0);
|
||||
}
|
||||
assert(tf.m_yieldLockCount == 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue