Skip to content

Commit

Permalink
Merge pull request #415 from vibe-d/fix_manualevent_in_non_d_threads
Browse files Browse the repository at this point in the history
Avoid unnecessarily creating event driver instances in non-D threads.
  • Loading branch information
l-kramer authored Oct 3, 2024
2 parents b886d90 + e4505e7 commit 85a491d
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions source/vibe/core/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -1379,17 +1379,18 @@ struct ManualEvent {
auto thisthr = Thread.getThis();

ThreadWaiter lw;
auto drv = eventDriver;
m_waiters.lock.active.iterate((ThreadWaiter w) {
debug (VibeMutexLog) () @trusted { logTrace("waiter %s", cast(void*)w); } ();
if (w.driver is drv) {
lw = w;
lw.addRef();
} else {
w.triggerEvent();
}
return true;
});
if (auto drv = tryGetEventDriver) {
m_waiters.lock.active.iterate((ThreadWaiter w) {
debug (VibeMutexLog) () @trusted { logTrace("waiter %s", cast(void*)w); } ();
if (w.driver is drv) {
lw = w;
lw.addRef();
} else {
w.triggerEvent();
}
return true;
});
}
debug (VibeMutexLog) () @trusted { logTrace("lw %s", cast(void*)lw); } ();
if (lw) {
lw.emit();
Expand All @@ -1412,18 +1413,19 @@ struct ManualEvent {
auto thisthr = Thread.getThis();

ThreadWaiter lw;
auto drv = eventDriver;
m_waiters.lock.active.iterate((ThreadWaiter w) {
() @trusted { logTrace("waiter %s", cast(void*)w); } ();
if (w.driver is drv) {
if (w.unused) return true;
lw = w;
lw.addRef();
} else {
w.triggerEvent();
}
return false;
});
if (auto drv = tryGetEventDriver) {
m_waiters.lock.active.iterate((ThreadWaiter w) {
() @trusted { logTrace("waiter %s", cast(void*)w); } ();
if (w.driver is drv) {
if (w.unused) return true;
lw = w;
lw.addRef();
} else {
w.triggerEvent();
}
return false;
});
}
() @trusted { logTrace("lw %s", cast(void*)lw); } ();
if (lw) {
lw.emitSingle();
Expand Down Expand Up @@ -1502,7 +1504,7 @@ struct ManualEvent {
private void acquireThreadWaiter(DEL)(scope DEL del)
shared {
ThreadWaiter w;
auto drv = eventDriver;
auto drv = tryGetEventDriver;

with (m_waiters.lock) {
active.iterate((aw) {
Expand Down

0 comments on commit 85a491d

Please sign in to comment.