]>
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)
7 // Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/unix/private/wakeuppipe.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 #define TRACE_EVENTS wxT("events")
39 // ============================================================================
40 // wxWakeUpPipe implementation
41 // ============================================================================
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxWakeUpPipe::wxWakeUpPipe()
51 if ( !m_pipe
.Create() )
53 wxLogError(_("Failed to create wake up pipe used by event loop."));
58 if ( !m_pipe
.MakeNonBlocking(wxPipe::Read
) )
60 wxLogSysError(_("Failed to switch wake up pipe to non-blocking mode"));
64 wxLogTrace(TRACE_EVENTS
, wxT("Wake up pipe (%d, %d) created"),
65 m_pipe
[wxPipe::Read
], m_pipe
[wxPipe::Write
]);
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 void wxWakeUpPipe::WakeUpNoLock()
74 // No need to do anything if the pipe already contains something.
78 if ( write(m_pipe
[wxPipe::Write
], "s", 1) != 1 )
80 // don't use wxLog here, we can be in another thread and this could
81 // result in dead locks
82 perror("write(wake up pipe)");
86 // We just wrote to it, so it's not empty any more.
87 m_pipeIsEmpty
= false;
91 void wxWakeUpPipe::OnReadWaiting()
93 // got wakeup from child thread, remove the data that provoked it from the
99 const int size
= read(GetReadFd(), buf
, WXSIZEOF(buf
));
103 wxASSERT_MSG( size
== 1, "Too many writes to wake-up pipe?" );
108 if ( size
== 0 || (size
== -1 && errno
== EAGAIN
) )
110 // No data available, not an error (but still surprising,
115 if ( errno
== EINTR
)
117 // We were interrupted, try again.
121 wxLogSysError(_("Failed to read from wake-up pipe"));
126 // The pipe is empty now, so future calls to WakeUp() would need to write
128 m_pipeIsEmpty
= true;