From fc96ee90504509956a6466b8da67d64ead909d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 27 Jan 2017 22:50:29 +0100 Subject: [PATCH] Fixes for setTimer and SpinLock. - setTimer now starts a task to call the callback. This keeps the timer referenced and avoids issues if I/O functions are called from within the callback. - SpinLock is now also initialized in "shared static this", so that applications using "shared static this" for initialization work properly. --- source/vibe/core/core.d | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index 190fc71..a03cd0d 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -872,8 +872,10 @@ Timer createTimer(void delegate() nothrow @safe callback) @safe nothrow { auto ret = Timer(eventDriver.timers.create()); if (callback !is null) { - void cb(TimerID tm) nothrow @safe { callback(); } - eventDriver.timers.wait(ret.m_id, &cb); // FIXME: avoid heap closure! + runTask((void delegate() nothrow @safe cb, Timer tm) { + tm.wait(); + cb(); + }, callback, ret); } return ret; } @@ -1302,6 +1304,9 @@ shared static this() import std.concurrency; scheduler = new VibedScheduler; + + import vibe.core.sync : SpinLock; + SpinLock.setup(); } shared static ~this()