]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/unix/private/wakeuppipe.h
Extract PipeIOHandler class into a header and rename to wxWakeUpPipe.
[wxWidgets.git] / include / wx / unix / private / wakeuppipe.h
... / ...
CommitLineData
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)
6// RCS-ID: $Id$
7// Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_UNIX_PRIVATE_WAKEUPPIPE_H_
12#define _WX_UNIX_PRIVATE_WAKEUPPIPE_H_
13
14#include "wx/private/fdiohandler.h"
15
16#include "wx/unix/pipe.h"
17
18// ----------------------------------------------------------------------------
19// wxWakeUpPipe: allows to wake up the event loop by writing to it
20// ----------------------------------------------------------------------------
21
22class wxWakeUpPipe : public wxFDIOHandler
23{
24public:
25 // Create and initialize the pipe.
26 //
27 // It's the callers responsibility to add the read end of this pipe,
28 // returned by GetReadFd(), to the code blocking on input.
29 wxWakeUpPipe();
30
31 // Wake up the blocking operation involving this pipe.
32 //
33 // It simply writes to the write end of the pipe.
34 //
35 // Notice that this method can be, and often is, called from another
36 // thread.
37 void WakeUp();
38
39 // Return the read end of the pipe.
40 int GetReadFd() { return m_pipe[wxPipe::Read]; }
41
42
43 // implement wxFDIOHandler pure virtual methods
44 virtual void OnReadWaiting();
45 virtual void OnWriteWaiting() { }
46 virtual void OnExceptionWaiting() { }
47
48private:
49 wxPipe m_pipe;
50
51 // Protects access to m_pipeIsEmpty.
52 wxCriticalSection m_pipeLock;
53
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.
58 bool m_pipeIsEmpty;
59};
60
61#endif // _WX_UNIX_PRIVATE_WAKEUPPIPE_H_