Skip to content

Commit

Permalink
Fix Config::getNextEvent() with definite timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Eilemann authored and Stefan Eilemann committed Aug 3, 2015
1 parent 028cad3 commit 6012916
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
2 changes: 2 additions & 0 deletions doc/Changelog.md
Expand Up @@ -3,6 +3,8 @@ Changelog {#Changelog}

# git master {#master}

* [481](https://github.com/Eyescale/Equalizer/pull/481):
Fix Config::getNextEvent() with definite timeout
* [467](https://github.com/Eyescale/Equalizer/issues/467):
Fix CPU load with idle Qt-based windows
* [479](https://github.com/Eyescale/Equalizer/pull/479):
Expand Down
3 changes: 2 additions & 1 deletion eq/base.h
@@ -1,5 +1,5 @@

/* Copyright (c) 2010-2013, Stefan Eilemann <eile@eyescale.ch>
/* Copyright (c) 2010-2015, Stefan Eilemann <eile@eyescale.ch>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
Expand Down Expand Up @@ -96,6 +96,7 @@
#include <eq/init.h>
#include <eq/layout.h>
#include <eq/log.h>
#include <eq/messagePump.h>
#include <eq/node.h>
#include <eq/nodeFactory.h>
#include <eq/observer.h>
Expand Down
46 changes: 27 additions & 19 deletions eq/commandQueue.cpp
@@ -1,6 +1,6 @@

/* Copyright (c) 2007-2013, Stefan Eilemann <eile@equalizergraphics.com>
* 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
/* Copyright (c) 2007-2015, Stefan Eilemann <eile@equalizergraphics.com>
* Daniel Nachbaur <danielnachbaur@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
Expand Down Expand Up @@ -59,67 +59,75 @@ void CommandQueue::pushFront( const co::ICommand& command )

co::ICommand CommandQueue::pop( const uint32_t timeout )
{
int64_t start = -1;
const int64_t start = _clock.getTime64();
int64_t waitBegin = -1;
while( true )
{
if( _messagePump )
_messagePump->dispatchAll(); // non-blocking

// Poll for a command
if( !isEmpty() || timeout == 0 )
if( !isEmpty( ))
{
if( start > -1 )
_waitTime += ( _clock.getTime64() - start );
return co::CommandQueue::pop( timeout );
if( waitBegin > -1 )
_waitTime += ( _clock.getTime64() - waitBegin );
return co::CommandQueue::pop( 0 );
}

if( _messagePump )
{
if( start == -1 )
start = _clock.getTime64();
if( waitBegin == -1 )
waitBegin = _clock.getTime64();
_messagePump->dispatchOne( timeout ); // blocks - push sends wakeup
}
else
{
start = _clock.getTime64();
waitBegin = _clock.getTime64();
// blocking
const co::ICommand& command = co::CommandQueue::pop( timeout );
_waitTime += ( _clock.getTime64() - start );
_waitTime += ( _clock.getTime64() - waitBegin );
return command;
}

if( _clock.getTime64() - start > timeout )
return co::ICommand();
}
}

co::ICommands CommandQueue::popAll( const uint32_t timeout )
{
int64_t start = -1;
const int64_t start = _clock.getTime64();
int64_t waitBegin = -1;
while( true )
{
if( _messagePump )
_messagePump->dispatchAll(); // non-blocking

// Poll for commands
if( !isEmpty() || timeout == 0 )
if( !isEmpty( ))
{
if( start > -1 )
_waitTime += ( _clock.getTime64() - start );
if( waitBegin > -1 )
_waitTime += ( _clock.getTime64() - waitBegin );
return co::CommandQueue::popAll( 0 );
}

if( _messagePump )
{
if( start == -1 )
start = _clock.getTime64();
if( waitBegin == -1 )
waitBegin = _clock.getTime64();
_messagePump->dispatchOne( timeout ); // blocks - push sends wakeup
}
else
{
start = _clock.getTime64();
waitBegin = _clock.getTime64();
// blocking
const co::ICommands& commands = co::CommandQueue::popAll( timeout );
_waitTime += ( _clock.getTime64() - start );
_waitTime += ( _clock.getTime64() - waitBegin );
return commands;
}

if( _clock.getTime64() - start > timeout )
return co::ICommands();
}
}

Expand Down

0 comments on commit 6012916

Please sign in to comment.