Qt 4.8
Public Functions | Public Variables | List of all members
QEventDispatcherUNIXPrivate Class Reference

#include <qeventdispatcher_unix_p.h>

Inheritance diagram for QEventDispatcherUNIXPrivate:
QAbstractEventDispatcherPrivate QObjectPrivate QObjectData QEventDispatcherBlackberryPrivate QEventDispatcherQPAPrivate QEventDispatcherQWSPrivate QEventDispatcherX11Private

Public Functions

int doSelect (QEventLoop::ProcessEventsFlags flags, timeval *timeout)
 
virtual int initThreadWakeUp ()
 
virtual int processThreadWakeUp (int nsel)
 
 QEventDispatcherUNIXPrivate ()
 
 ~QEventDispatcherUNIXPrivate ()
 
- Public Functions inherited from QAbstractEventDispatcherPrivate
void init ()
 
 QAbstractEventDispatcherPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

bool interrupt
 
bool mainThread
 
int sn_highest
 
QSockNotType::List sn_pending_list
 
QSockNotType sn_vec [3]
 
int thread_pipe [2]
 
QTimerInfoList timerList
 
QAtomicInt wakeUps
 
- Public Variables inherited from QAbstractEventDispatcherPrivate
QAbstractEventDispatcher::EventFilter event_filter
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QAbstractEventDispatcherPrivate
static int allocateTimerId ()
 
static void releaseTimerId (int id)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 177 of file qeventdispatcher_unix_p.h.

Constructors and Destructors

◆ QEventDispatcherUNIXPrivate()

QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate ( )

Definition at line 108 of file qeventdispatcher_unix.cpp.

109 {
112  bool pipefail = false;
113 
114  // initialize the common parts of the event loop
115 #if defined(Q_OS_NACL) || defined (Q_OS_BLACKBERRY)
116  // do nothing.
117 #elif defined(Q_OS_INTEGRITY)
118  // INTEGRITY doesn't like a "select" on pipes, so use socketpair instead
119  if (socketpair(AF_INET, SOCK_STREAM, 0, thread_pipe) == -1) {
120  perror("QEventDispatcherUNIXPrivate(): Unable to create socket pair");
121  pipefail = true;
122  } else {
123  initThreadPipeFD(thread_pipe[0]);
124  initThreadPipeFD(thread_pipe[1]);
125  }
126 #elif defined(Q_OS_VXWORKS)
127  char name[20];
128  qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf()));
129 
130  // make sure there is no pipe with this name
131  pipeDevDelete(name, true);
132  // create the pipe
133  if (pipeDevCreate(name, 128 /*maxMsg*/, 1 /*maxLength*/) != OK) {
134  perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe device");
135  pipefail = true;
136  } else {
137  if ((thread_pipe[0] = open(name, O_RDWR, 0)) < 0) {
138  perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe");
139  pipefail = true;
140  } else {
141  initThreadPipeFD(thread_pipe[0]);
142  thread_pipe[1] = thread_pipe[0];
143  }
144  }
145 #else
146  if (qt_safe_pipe(thread_pipe, O_NONBLOCK) == -1) {
147  perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe");
148  pipefail = true;
149  }
150 #endif
151 
152  if (pipefail)
153  qFatal("QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe");
154 
155  sn_highest = -1;
156 
157  interrupt = false;
158 }
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
const char * name
static int qt_safe_pipe(int pipefd[2], int flags=0)
Definition: qcore_unix_p.h:191
void * HANDLE
Definition: qnamespace.h:1671
Q_CORE_EXPORT void qFatal(const char *,...)
#define O_RDWR
Qt::HANDLE qt_application_thread_id
int open(const char *, int,...)
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ ~QEventDispatcherUNIXPrivate()

QEventDispatcherUNIXPrivate::~QEventDispatcherUNIXPrivate ( )

Definition at line 160 of file qeventdispatcher_unix.cpp.

161 {
162 #if defined(Q_OS_NACL) || defined (Q_OS_BLACKBERRY)
163  // do nothing.
164 #elif defined(Q_OS_VXWORKS)
165  close(thread_pipe[0]);
166 
167  char name[20];
168  qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf()));
169 
170  pipeDevDelete(name, true);
171 #else
172  // cleanup the common parts of the event loop
173  close(thread_pipe[0]);
174  close(thread_pipe[1]);
175 #endif
176 
177  // cleanup timers
179 }
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
const char * name
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

Functions

◆ doSelect()

int QEventDispatcherUNIXPrivate::doSelect ( QEventLoop::ProcessEventsFlags  flags,
timeval *  timeout 
)

Definition at line 181 of file qeventdispatcher_unix.cpp.

182 {
184 
185  // needed in QEventDispatcherUNIX::select()
187 
188  int nsel;
189  do {
190  if (mainThread) {
191  while (signal_received) {
192  signal_received = 0;
193  for (int i = 0; i < NSIG; ++i) {
194  if (signals_fired[i]) {
195  signals_fired[i] = 0;
197  }
198  }
199  }
200  }
201 
202  // Process timers and socket notifiers - the common UNIX stuff
203  int highest = 0;
204  if (! (flags & QEventLoop::ExcludeSocketNotifiers) && (sn_highest >= 0)) {
205  // return the highest fd we can wait for input on
209  highest = sn_highest;
210  } else {
211  FD_ZERO(&sn_vec[0].select_fds);
212  FD_ZERO(&sn_vec[1].select_fds);
213  FD_ZERO(&sn_vec[2].select_fds);
214  }
215 
216  int wakeUpFd = initThreadWakeUp();
217  highest = qMax(highest, wakeUpFd);
218 
219  nsel = q->select(highest + 1,
220  &sn_vec[0].select_fds,
221  &sn_vec[1].select_fds,
222  &sn_vec[2].select_fds,
223  timeout);
224  } while (nsel == -1 && (errno == EINTR || errno == EAGAIN));
225 
226  if (nsel == -1) {
227  if (errno == EBADF) {
228  // it seems a socket notifier has a bad fd... find out
229  // which one it is and disable it
230  fd_set fdset;
231  timeval tm;
232  tm.tv_sec = tm.tv_usec = 0l;
233 
234  for (int type = 0; type < 3; ++type) {
236  if (list.size() == 0)
237  continue;
238 
239  for (int i = 0; i < list.size(); ++i) {
240  QSockNot *sn = list[i];
241 
242  FD_ZERO(&fdset);
243  FD_SET(sn->fd, &fdset);
244 
245  int ret = -1;
246  do {
247  switch (type) {
248  case 0: // read
249  ret = select(sn->fd + 1, &fdset, 0, 0, &tm);
250  break;
251  case 1: // write
252  ret = select(sn->fd + 1, 0, &fdset, 0, &tm);
253  break;
254  case 2: // except
255  ret = select(sn->fd + 1, 0, 0, &fdset, &tm);
256  break;
257  }
258  } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
259 
260  if (ret == -1 && errno == EBADF) {
261  // disable the invalid socket notifier
262  static const char *t[] = { "Read", "Write", "Exception" };
263  qWarning("QSocketNotifier: Invalid socket %d and type '%s', disabling...",
264  sn->fd, t[type]);
265  sn->obj->setEnabled(false);
266  }
267  }
268  }
269  } else {
270  // EINVAL... shouldn't happen, so let's complain to stderr
271  // and hope someone sends us a bug report
272  perror("select");
273  }
274  }
275 
276  int nevents = processThreadWakeUp(nsel);
277 
278  // activate socket notifiers
279  if (! (flags & QEventLoop::ExcludeSocketNotifiers) && nsel > 0 && sn_highest >= 0) {
280  // if select says data is ready on any socket, then set the socket notifier
281  // to pending
282  for (int i=0; i<3; i++) {
283  QSockNotType::List &list = sn_vec[i].list;
284  for (int j = 0; j < list.size(); ++j) {
285  QSockNot *sn = list[j];
286  if (FD_ISSET(sn->fd, &sn_vec[i].select_fds))
287  q->setSocketNotifierPending(sn->obj);
288  }
289  }
290  }
291  return (nevents + q->activateSocketNotifiers());
292 }
static sig_atomic_t signal_received
QSocketNotifier * obj
int type
Definition: qmetatype.cpp:239
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
void unixSignal(int)
This signal is emitted whenever a Unix signal is received by the application.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define Q_Q(Class)
Definition: qglobal.h:2483
static sig_atomic_t signals_fired[NSIG]
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
QFactoryLoader * l
virtual int processThreadWakeUp(int nsel)
int size() const
int errno

◆ initThreadWakeUp()

int QEventDispatcherUNIXPrivate::initThreadWakeUp ( )
virtual

Reimplemented in QEventDispatcherBlackberryPrivate.

Definition at line 294 of file qeventdispatcher_unix.cpp.

Referenced by doSelect().

295 {
296  FD_SET(thread_pipe[0], &sn_vec[0].select_fds);
297  return thread_pipe[0];
298 }

◆ processThreadWakeUp()

int QEventDispatcherUNIXPrivate::processThreadWakeUp ( int  nsel)
virtual

Reimplemented in QEventDispatcherBlackberryPrivate.

Definition at line 300 of file qeventdispatcher_unix.cpp.

Referenced by doSelect().

301 {
302  if (nsel > 0 && FD_ISSET(thread_pipe[0], &sn_vec[0].select_fds)) {
303  // some other thread woke us up... consume the data on the thread pipe so that
304  // select doesn't immediately return next time
305 #if defined(Q_OS_VXWORKS)
306  char c[16];
307  ::read(thread_pipe[0], c, sizeof(c));
308  ::ioctl(thread_pipe[0], FIOFLUSH, 0);
309 #else
310  char c[16];
311  while (::read(thread_pipe[0], c, sizeof(c)) > 0)
312  ;
313 #endif
314  if (!wakeUps.testAndSetRelease(1, 0)) {
315  // hopefully, this is dead code
316  qWarning("QEventDispatcherUNIX: internal error, wakeUps.testAndSetRelease(1, 0) failed!");
317  }
318  return 1;
319  }
320  return 0;
321 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool testAndSetRelease(int expectedValue, int newValue)
Atomic test-and-set.
Q_CORE_EXPORT void qWarning(const char *,...)

Properties

◆ interrupt

bool QEventDispatcherUNIXPrivate::interrupt

Definition at line 203 of file qeventdispatcher_unix_p.h.

Referenced by QEventDispatcherUNIXPrivate().

◆ mainThread

bool QEventDispatcherUNIXPrivate::mainThread

Definition at line 189 of file qeventdispatcher_unix_p.h.

Referenced by doSelect(), and QEventDispatcherUNIXPrivate().

◆ sn_highest

int QEventDispatcherUNIXPrivate::sn_highest

Definition at line 193 of file qeventdispatcher_unix_p.h.

Referenced by doSelect(), and QEventDispatcherUNIXPrivate().

◆ sn_pending_list

QSockNotType::List QEventDispatcherUNIXPrivate::sn_pending_list

Definition at line 200 of file qeventdispatcher_unix_p.h.

◆ sn_vec

QSockNotType QEventDispatcherUNIXPrivate::sn_vec[3]

Definition at line 195 of file qeventdispatcher_unix_p.h.

Referenced by doSelect(), initThreadWakeUp(), and processThreadWakeUp().

◆ thread_pipe

int QEventDispatcherUNIXPrivate::thread_pipe[2]

◆ timerList

QTimerInfoList QEventDispatcherUNIXPrivate::timerList

Definition at line 197 of file qeventdispatcher_unix_p.h.

Referenced by doSelect(), and ~QEventDispatcherUNIXPrivate().

◆ wakeUps

QAtomicInt QEventDispatcherUNIXPrivate::wakeUps

The documentation for this class was generated from the following files: