Skip to content

Commit 0cdddc4

Browse files
authored
Merge pull request #243 from vibe-d/windowseventids
Use a global event ID counter on Windows
2 parents 3cdca04 + 16da4af commit 0cdddc4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

source/eventcore/drivers/winapi/events.d

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class WinAPIEventDriverEvents : EventDriverEvents {
3030
EventSlot[EventID] m_events;
3131
CRITICAL_SECTION m_mutex;
3232
ConsumableQueue!Trigger m_pending;
33-
uint m_idCounter;
33+
static shared uint m_idCounter;
3434
}
3535

3636
this(WinAPIEventDriverCore core)
@@ -70,8 +70,10 @@ final class WinAPIEventDriverEvents : EventDriverEvents {
7070

7171
override EventID create()
7272
{
73-
auto id = EventID(m_idCounter++, 0);
74-
if (id == EventID.invalid) id = EventID(m_idCounter++, 0);
73+
import core.atomic : atomicOp;
74+
75+
auto id = EventID(atomicOp!"+="(m_idCounter, 1), 0);
76+
if (id == EventID.invalid) id = EventID(atomicOp!"+="(m_idCounter, 1), 0);
7577
m_events[id] = EventSlot(1, new ConsumableQueue!EventCallback); // FIXME: avoid GC allocation
7678
debug (EventCoreLeakTrace) {
7779
import core.runtime : defaultTraceHandler;

0 commit comments

Comments
 (0)