1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/private/wakeuppipe.h
3 // Purpose: Helper class allowing to wake up the main thread.
4 // Author: Vadim Zeitlin
5 // Created: 2013-06-09 (extracted from src/unix/evtloopunix.cpp)
7 // Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIX_PRIVATE_WAKEUPPIPE_H_
12 #define _WX_UNIX_PRIVATE_WAKEUPPIPE_H_
14 #include "wx/private/fdiohandler.h"
16 #include "wx/unix/pipe.h"
18 // ----------------------------------------------------------------------------
19 // wxWakeUpPipe: allows to wake up the event loop by writing to it
20 // ----------------------------------------------------------------------------
22 class wxWakeUpPipe
: public wxFDIOHandler
25 // Create and initialize the pipe.
27 // It's the callers responsibility to add the read end of this pipe,
28 // returned by GetReadFd(), to the code blocking on input.
31 // Wake up the blocking operation involving this pipe.
33 // It simply writes to the write end of the pipe.
35 // Notice that this method can be, and often is, called from another
39 // Return the read end of the pipe.
40 int GetReadFd() { return m_pipe
[wxPipe::Read
]; }
43 // implement wxFDIOHandler pure virtual methods
44 virtual void OnReadWaiting();
45 virtual void OnWriteWaiting() { }
46 virtual void OnExceptionWaiting() { }
51 // Protects access to m_pipeIsEmpty.
52 wxCriticalSection m_pipeLock
;
54 // This flag is set to true after writing to the pipe and reset to false
55 // after reading from it in the main thread. Having it allows us to avoid
56 // overflowing the pipe with too many writes if the main thread can't keep
57 // up with reading from it.
61 #endif // _WX_UNIX_PRIVATE_WAKEUPPIPE_H_