Skip to content

Commit

Permalink
Added EventDriver.runEventLoopOnce() and fixed yieldForEvent() outsid…
Browse files Browse the repository at this point in the history
…e of a fiber to use it and block if necessary.
  • Loading branch information
s-ludwig committed Jul 15, 2012
1 parent d12e862 commit 9bcbae8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/vibe/core/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private class VibeDriverCore : DriverCore {
}
} else {
assert(!s_eventLoopRunning, "Event processing outside of a fiber should only happen before the event loop is running!?");
if( auto err = s_driver.processEvents() != 0){
if( auto err = s_driver.runEventLoopOnce() ){
if( err == 1 ){
logDebug("No events registered, exiting event loop.");
throw new Exception("No events registered in vibeYieldForEvent.");
Expand Down
7 changes: 5 additions & 2 deletions source/vibe/core/driver.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ interface EventDriver {
*/
int runEventLoop();

/** Processes all outstanding events, potentially blocking until the first event comes
available.
/* Processes all outstanding events, potentially blocking to wait for the first event.
*/
int runEventLoopOnce();

/** Processes all outstanding events if any, does not block.
*/
int processEvents();

Expand Down
7 changes: 7 additions & 0 deletions source/vibe/core/drivers/libev.d
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class LibevDriver : EventDriver {
return 0;
}

int runEventLoopOnce()
{
ev_run(m_loop, EVRUN_ONCE);
m_core.notifyIdle();
return 0;
}

int processEvents()
{
ev_run(m_loop, EVRUN_NOWAIT);
Expand Down
7 changes: 7 additions & 0 deletions source/vibe/core/drivers/libevent2.d
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ class Libevent2Driver : EventDriver {
return ret;
}

int runEventLoopOnce()
{
auto ret = event_base_loop(m_eventLoop, EVLOOP_ONCE);
m_core.notifyIdle();
return ret;
}

int processEvents()
{
auto ret = event_base_loop(m_eventLoop, EVLOOP_NONBLOCK);
Expand Down
5 changes: 5 additions & 0 deletions source/vibe/core/drivers/win32.d
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class Win32EventDriver : EventDriver {
int processEvents()
{
waitForEvents(0);
return processEvents();
}

int processEvents()
{
MSG msg;
while( PeekMessageW(&msg, null, 0, 0, PM_REMOVE) ){
if( msg.message == WM_QUIT ) return 0;
Expand Down
5 changes: 5 additions & 0 deletions source/vibe/core/drivers/winrt.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class WinRtEventDriver : EventDriver {
return 0;
}

int runEventLoopOnce()
{
return 0;
}

int processEvents()
{
return 0;
Expand Down

0 comments on commit 9bcbae8

Please sign in to comment.