]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/wakeuppipe.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/wakeuppipe.cpp
3 // Purpose: Implementation of wxWakeUpPipe class.
4 // Author: Vadim Zeitlin
5 // Created: 2013-06-09 (extracted from src/unix/evtloopunix.cpp)
6 // Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
28 #include "wx/unix/private/wakeuppipe.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 #define TRACE_EVENTS wxT("events")
38 // ============================================================================
39 // wxWakeUpPipe implementation
40 // ============================================================================
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 wxWakeUpPipe::wxWakeUpPipe()
50 if ( !m_pipe
.Create() )
52 wxLogError(_("Failed to create wake up pipe used by event loop."));
57 if ( !m_pipe
.MakeNonBlocking(wxPipe::Read
) )
59 wxLogSysError(_("Failed to switch wake up pipe to non-blocking mode"));
63 wxLogTrace(TRACE_EVENTS
, wxT("Wake up pipe (%d, %d) created"),
64 m_pipe
[wxPipe::Read
], m_pipe
[wxPipe::Write
]);
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 void wxWakeUpPipe::WakeUpNoLock()
73 // No need to do anything if the pipe already contains something.
77 if ( write(m_pipe
[wxPipe::Write
], "s", 1) != 1 )
79 // don't use wxLog here, we can be in another thread and this could
80 // result in dead locks
81 perror("write(wake up pipe)");
85 // We just wrote to it, so it's not empty any more.
86 m_pipeIsEmpty
= false;
90 void wxWakeUpPipe::OnReadWaiting()
92 // got wakeup from child thread, remove the data that provoked it from the
98 const int size
= read(GetReadFd(), buf
, WXSIZEOF(buf
));
102 wxASSERT_MSG( size
== 1, "Too many writes to wake-up pipe?" );
107 if ( size
== 0 || (size
== -1 && errno
== EAGAIN
) )
109 // No data available, not an error (but still surprising,
114 if ( errno
== EINTR
)
116 // We were interrupted, try again.
120 wxLogSysError(_("Failed to read from wake-up pipe"));
125 // The pipe is empty now, so future calls to WakeUp() would need to write
127 m_pipeIsEmpty
= true;