From 910451557b3c62f37f2790b9c815d64754e9aef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 16 Mar 2018 13:34:27 +0100 Subject: [PATCH] Add test for runInOwnerThread. --- tests/0-runinownerthread.d | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/0-runinownerthread.d diff --git a/tests/0-runinownerthread.d b/tests/0-runinownerthread.d new file mode 100644 index 0000000..bb9208e --- /dev/null +++ b/tests/0-runinownerthread.d @@ -0,0 +1,37 @@ +/++ dub.sdl: + name "test" + dependency "eventcore" path=".." ++/ +module test; + +import eventcore.core; +import core.thread; +import std.stdint; + +intptr_t s_id; // thread-local + +void main() +{ + auto ed = cast(shared)eventDriver; + + auto thr = new Thread({ threadFunc(ed); }); + thr.start(); + + // keep the event loop running for one second + auto tm = eventDriver.timers.create(); + eventDriver.timers.set(tm, 1.seconds, 0.seconds); + + ExitReason er; + do er = eventDriver.core.processEvents(Duration.max); + while (er == ExitReason.idle); + assert(er == ExitReason.outOfWaiters); + + assert(s_id == 42); +} + +void threadFunc(shared(NativeEventDriver) drv) +{ + drv.core.runInOwnerThread((id) { + s_id = id; + }, 42); +}