fix windows build and refactor last addition to EventQueue
This commit is contained in:
parent
d9530bf7aa
commit
830f6acbef
|
@ -201,14 +201,20 @@ EventQueue::adoptBuffer(IEventQueueBuffer* buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
EventQueue::parent_requests_shutdown() const
|
||||||
|
{
|
||||||
|
char ch;
|
||||||
|
return m_parentStream.try_read_char(ch) && ch == ShutdownCh;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
EventQueue::getEvent(Event& event, double timeout)
|
EventQueue::getEvent(Event& event, double timeout)
|
||||||
{
|
{
|
||||||
Stopwatch timer(true);
|
Stopwatch timer(true);
|
||||||
retry:
|
retry:
|
||||||
// check to see if parent wants us to shutdown now
|
// before handling any events make sure we don't need to shutdown
|
||||||
char ch;
|
if (parent_requests_shutdown()) {
|
||||||
if (m_parentStream.try_read_char(ch) && ch == ShutdownCh) {
|
|
||||||
event = Event(Event::kQuit);
|
event = Event(Event::kQuit);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ private:
|
||||||
bool hasTimerExpired(Event& event);
|
bool hasTimerExpired(Event& event);
|
||||||
double getNextTimerTimeout() const;
|
double getNextTimerTimeout() const;
|
||||||
void addEventToBuffer(const Event& event);
|
void addEventToBuffer(const Event& event);
|
||||||
|
bool parent_requests_shutdown() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Timer {
|
class Timer {
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
|
|
||||||
#include "base/NonBlockingStream.h"
|
#include "base/NonBlockingStream.h"
|
||||||
|
|
||||||
#include <unistd.h> // tcgetattr/tcsetattr, read
|
#include <unistd.h> // tcgetattr/tcsetattr, read
|
||||||
|
@ -46,7 +48,7 @@ NonBlockingStream::~NonBlockingStream()
|
||||||
delete _p_ta_previous;
|
delete _p_ta_previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NonBlockingStream::try_read_char(char &ch)
|
bool NonBlockingStream::try_read_char(char &ch) const
|
||||||
{
|
{
|
||||||
int result = read(_fd, &ch, 1);
|
int result = read(_fd, &ch, 1);
|
||||||
if (result == 1)
|
if (result == 1)
|
||||||
|
@ -54,3 +56,5 @@ bool NonBlockingStream::try_read_char(char &ch)
|
||||||
assert(result == -1 && (errno == EAGAIN || errno == EWOULDBLOCK));
|
assert(result == -1 && (errno == EAGAIN || errno == EWOULDBLOCK));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // !defined(_WIN32)
|
||||||
|
|
|
@ -17,6 +17,19 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// windows doesn't have a unistd.h so this class won't work as-written.
|
||||||
|
// at the moment barrier doesn't need this functionality on windows so
|
||||||
|
// it's left as a stub to be optimized out
|
||||||
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
class NonBlockingStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool try_read_char(char &ch) const { return false; };
|
||||||
|
};
|
||||||
|
|
||||||
|
#else // non-windows platforms
|
||||||
|
|
||||||
struct termios;
|
struct termios;
|
||||||
|
|
||||||
class NonBlockingStream
|
class NonBlockingStream
|
||||||
|
@ -25,10 +38,12 @@ public:
|
||||||
explicit NonBlockingStream(int fd = 0);
|
explicit NonBlockingStream(int fd = 0);
|
||||||
~NonBlockingStream();
|
~NonBlockingStream();
|
||||||
|
|
||||||
bool try_read_char(char &ch);
|
bool try_read_char(char &ch) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _fd;
|
int _fd;
|
||||||
termios * _p_ta_previous;
|
termios * _p_ta_previous;
|
||||||
int _cntl_previous;
|
int _cntl_previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue