summaryrefslogtreecommitdiff
path: root/src/NextEvent.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2019-06-13 18:28:58 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2019-06-13 18:30:39 -0400
commit86073013496a2f45ebde242001e82cf5049d51cd (patch)
treee944e5422828c62db344ebb0a4bdcd5dfce5cdc6 /src/NextEvent.c
parent190c027e3e594afb15c6d613d95ce5af9e22fcf7 (diff)
reduce ifdef/ifndef inconsistency for USE_POLL
Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
Diffstat (limited to 'src/NextEvent.c')
-rw-r--r--src/NextEvent.c222
1 files changed, 111 insertions, 111 deletions
diff --git a/src/NextEvent.c b/src/NextEvent.c
index 75e74ad..5e96173 100644
--- a/src/NextEvent.c
+++ b/src/NextEvent.c
@@ -167,19 +167,19 @@ typedef struct {
struct timeval new_time;
struct timeval time_spent;
struct timeval max_wait_time;
-#ifndef USE_POLL
- struct timeval *wait_time_ptr;
-#else
+#ifdef USE_POLL
int poll_wait;
+#else
+ struct timeval *wait_time_ptr;
#endif
} wait_times_t, *wait_times_ptr_t;
static struct timeval zero_time = { 0 , 0};
-#ifndef USE_POLL
-static fd_set zero_fd;
-#else
+#ifdef USE_POLL
#define X_BLOCK -1
#define X_DONT_BLOCK 0
+#else
+static fd_set zero_fd;
#endif
static void InitTimes (
@@ -192,38 +192,38 @@ static void InitTimes (
FIXUP_TIMEVAL(wt->cur_time);
wt->start_time = wt->cur_time;
if(howlong == NULL) { /* special case for ever */
-#ifndef USE_POLL
- wt->wait_time_ptr = NULL;
-#else
+#ifdef USE_POLL
wt->poll_wait = X_BLOCK;
+#else
+ wt->wait_time_ptr = NULL;
#endif
} else { /* block until at most */
wt->max_wait_time.tv_sec = (time_t) (*howlong/1000);
wt->max_wait_time.tv_usec = (suseconds_t) ((*howlong %1000)*1000);
-#ifndef USE_POLL
- wt->wait_time_ptr = &wt->max_wait_time;
-#else
+#ifdef USE_POLL
wt->poll_wait = (int) *howlong;
+#else
+ wt->wait_time_ptr = &wt->max_wait_time;
#endif
}
} else { /* don't block */
wt->max_wait_time = zero_time;
-#ifndef USE_POLL
- wt->wait_time_ptr = &wt->max_wait_time;
-#else
+#ifdef USE_POLL
wt->poll_wait = X_DONT_BLOCK;
+#else
+ wt->wait_time_ptr = &wt->max_wait_time;
#endif
}
}
typedef struct {
-#ifndef USE_POLL
- fd_set rmask, wmask, emask;
- int nfds;
-#else
+#ifdef USE_POLL
struct pollfd* fdlist;
struct pollfd* stack;
int fdlistlen, num_dpys;
+#else
+ fd_set rmask, wmask, emask;
+ int nfds;
#endif
} wait_fds_t, *wait_fds_ptr_t;
@@ -235,20 +235,7 @@ static void InitFds (
{
int ii;
app->rebuild_fdlist = FALSE;
-#ifndef USE_POLL
- wf->nfds = app->fds.nfds;
- if( !ignoreInputs ) {
- wf->rmask = app->fds.rmask;
- wf->wmask = app->fds.wmask;
- wf->emask = app->fds.emask;
- } else
- wf->rmask = wf->wmask = wf->emask = zero_fd;
-
- if (!ignoreEvents)
- for (ii = 0; ii < app->count; ii++) {
- FD_SET (ConnectionNumber(app->list[ii]), &wf->rmask);
- }
-#else
+#ifdef USE_POLL
#ifndef POLLRDNORM
#define POLLRDNORM 0
#endif
@@ -315,6 +302,19 @@ static void InitFds (
fdlp++;
}
}
+#else
+ wf->nfds = app->fds.nfds;
+ if( !ignoreInputs ) {
+ wf->rmask = app->fds.rmask;
+ wf->wmask = app->fds.wmask;
+ wf->emask = app->fds.emask;
+ } else
+ wf->rmask = wf->wmask = wf->emask = zero_fd;
+
+ if (!ignoreEvents)
+ for (ii = 0; ii < app->count; ii++) {
+ FD_SET (ConnectionNumber(app->list[ii]), &wf->rmask);
+ }
#endif
}
@@ -326,24 +326,24 @@ static void AdjustTimes (
wait_times_ptr_t wt)
{
if (app->timerQueue != NULL && !ignoreTimers && block) {
-#ifndef USE_POLL
+#ifdef USE_POLL
if (IS_AFTER (wt->cur_time, app->timerQueue->te_timer_value)) {
TIMEDELTA (wt->wait_time, app->timerQueue->te_timer_value, wt->cur_time);
if (howlong == NULL || IS_AFTER (wt->wait_time, wt->max_wait_time))
- wt->wait_time_ptr = &wt->wait_time;
+ wt->poll_wait = (int) (wt->wait_time.tv_sec * 1000 + wt->wait_time.tv_usec / 1000);
else
- wt->wait_time_ptr = &wt->max_wait_time;
+ wt->poll_wait = (int) (wt->max_wait_time.tv_sec * 1000 + wt->max_wait_time.tv_usec / 1000);
} else
- wt->wait_time_ptr = &zero_time;
+ wt->poll_wait = X_DONT_BLOCK;
#else
if (IS_AFTER (wt->cur_time, app->timerQueue->te_timer_value)) {
TIMEDELTA (wt->wait_time, app->timerQueue->te_timer_value, wt->cur_time);
if (howlong == NULL || IS_AFTER (wt->wait_time, wt->max_wait_time))
- wt->poll_wait = (int) (wt->wait_time.tv_sec * 1000 + wt->wait_time.tv_usec / 1000);
+ wt->wait_time_ptr = &wt->wait_time;
else
- wt->poll_wait = (int) (wt->max_wait_time.tv_sec * 1000 + wt->max_wait_time.tv_usec / 1000);
+ wt->wait_time_ptr = &wt->max_wait_time;
} else
- wt->poll_wait = X_DONT_BLOCK;
+ wt->wait_time_ptr = &zero_time;
#endif
}
}
@@ -353,11 +353,11 @@ static int IoWait (
wait_times_ptr_t wt,
wait_fds_ptr_t wf)
{
-#ifndef USE_POLL
+#ifdef USE_POLL
+ return poll (wf->fdlist, (nfds_t) wf->fdlistlen, wt->poll_wait);
+#else
return Select (wf->nfds, &wf->rmask, &wf->wmask, &wf->emask,
wt->wait_time_ptr);
-#else
- return poll (wf->fdlist, (nfds_t) wf->fdlistlen, wt->poll_wait);
#endif
}
@@ -373,7 +373,61 @@ static void FindInputs (
{
InputEvent *ep;
int ii;
-#ifndef USE_POLL /* { check ready file descriptors block */
+#ifdef USE_POLL /* { check ready file descriptors block */
+ struct pollfd* fdlp;
+
+ *dpy_no = -1;
+ *found_input = False;
+
+ if (!ignoreEvents) {
+ fdlp = wf->fdlist;
+ for (ii = 0; ii < wf->num_dpys; ii++, fdlp++) {
+ if (*dpy_no == -1 && fdlp->revents & (POLLIN|POLLHUP|POLLERR) &&
+#ifdef XTHREADS
+ !(fdlp->revents & POLLNVAL) &&
+#endif
+ XEventsQueued (app->list[ii], QueuedAfterReading)) {
+ *dpy_no = ii;
+ break;
+ }
+ }
+ }
+
+ if (!ignoreInputs) {
+ fdlp = &wf->fdlist[wf->num_dpys];
+ for (ii = wf->num_dpys; ii < wf->fdlistlen; ii++, fdlp++) {
+ XtInputMask condition = 0;
+ if (fdlp->revents) {
+ if (fdlp->revents & (XPOLL_READ|POLLHUP|POLLERR)
+#ifdef XTHREADS
+ && !(fdlp->revents & POLLNVAL)
+#endif
+ )
+ condition = XtInputReadMask;
+ if (fdlp->revents & XPOLL_WRITE)
+ condition |= XtInputWriteMask;
+ if (fdlp->revents & XPOLL_EXCEPT)
+ condition |= XtInputExceptMask;
+ }
+ if (condition) {
+ *found_input = True;
+ for (ep = app->input_list[fdlp->fd]; ep; ep = ep->ie_next)
+ if (condition & ep->ie_condition) {
+ InputEvent *oq;
+ /* make sure this input isn't already marked outstanding */
+ for (oq = app->outstandingQueue; oq; oq = oq->ie_oq)
+ if (oq == ep)
+ break;
+ if (!oq)
+ {
+ ep->ie_oq = app->outstandingQueue;
+ app->outstandingQueue = ep;
+ }
+ }
+ }
+ }
+ }
+#else /* }{ */
#ifdef XTHREADS
fd_set rmask;
#endif
@@ -452,60 +506,6 @@ static void FindInputs (
}
ENDILOOP: ;
} /* endfor */
-#else /* }{ */
- struct pollfd* fdlp;
-
- *dpy_no = -1;
- *found_input = False;
-
- if (!ignoreEvents) {
- fdlp = wf->fdlist;
- for (ii = 0; ii < wf->num_dpys; ii++, fdlp++) {
- if (*dpy_no == -1 && fdlp->revents & (POLLIN|POLLHUP|POLLERR) &&
-#ifdef XTHREADS
- !(fdlp->revents & POLLNVAL) &&
-#endif
- XEventsQueued (app->list[ii], QueuedAfterReading)) {
- *dpy_no = ii;
- break;
- }
- }
- }
-
- if (!ignoreInputs) {
- fdlp = &wf->fdlist[wf->num_dpys];
- for (ii = wf->num_dpys; ii < wf->fdlistlen; ii++, fdlp++) {
- XtInputMask condition = 0;
- if (fdlp->revents) {
- if (fdlp->revents & (XPOLL_READ|POLLHUP|POLLERR)
-#ifdef XTHREADS
- && !(fdlp->revents & POLLNVAL)
-#endif
- )
- condition = XtInputReadMask;
- if (fdlp->revents & XPOLL_WRITE)
- condition |= XtInputWriteMask;
- if (fdlp->revents & XPOLL_EXCEPT)
- condition |= XtInputExceptMask;
- }
- if (condition) {
- *found_input = True;
- for (ep = app->input_list[fdlp->fd]; ep; ep = ep->ie_next)
- if (condition & ep->ie_condition) {
- InputEvent *oq;
- /* make sure this input isn't already marked outstanding */
- for (oq = app->outstandingQueue; oq; oq = oq->ie_oq)
- if (oq == ep)
- break;
- if (!oq)
- {
- ep->ie_oq = app->outstandingQueue;
- app->outstandingQueue = ep;
- }
- }
- }
- }
- }
#endif /* } */
}
@@ -664,25 +664,25 @@ WaitLoop:
}
if (block) {
-#ifndef USE_POLL
- if (wt.wait_time_ptr == NULL)
-#else
+#ifdef USE_POLL
if (wt.poll_wait == X_BLOCK)
+#else
+ if (wt.wait_time_ptr == NULL)
#endif
continue;
X_GETTIMEOFDAY (&wt.new_time);
FIXUP_TIMEVAL (wt.new_time);
TIMEDELTA (wt.time_spent, wt.new_time, wt.cur_time);
wt.cur_time = wt.new_time;
-#ifndef USE_POLL
- if (IS_AFTER (wt.time_spent, *wt.wait_time_ptr)) {
- TIMEDELTA (wt.wait_time, *wt.wait_time_ptr, wt.time_spent);
- wt.wait_time_ptr = &wt.wait_time;
+#ifdef USE_POLL
+ if ((wt.time_spent.tv_sec * 1000 + wt.time_spent.tv_usec / 1000) < wt.poll_wait) {
+ wt.poll_wait -= (int)(wt.time_spent.tv_sec * 1000 + wt.time_spent.tv_usec / 1000);
continue;
} else
#else
- if ((wt.time_spent.tv_sec * 1000 + wt.time_spent.tv_usec / 1000) < wt.poll_wait) {
- wt.poll_wait -= (int)(wt.time_spent.tv_sec * 1000 + wt.time_spent.tv_usec / 1000);
+ if (IS_AFTER (wt.time_spent, *wt.wait_time_ptr)) {
+ TIMEDELTA (wt.wait_time, *wt.wait_time_ptr, wt.time_spent);
+ wt.wait_time_ptr = &wt.wait_time;
continue;
} else
#endif
@@ -1021,15 +1021,15 @@ XtInputId XtAppAddInput(
sptr->ie_next = app->input_list[source];
app->input_list[source] = sptr;
-#ifndef USE_POLL
+#ifdef USE_POLL
+ if (sptr->ie_next == NULL)
+ app->fds.nfds++;
+#else
if (condition & XtInputReadMask) FD_SET(source, &app->fds.rmask);
if (condition & XtInputWriteMask) FD_SET(source, &app->fds.wmask);
if (condition & XtInputExceptMask) FD_SET(source, &app->fds.emask);
if (app->fds.nfds < (source+1)) app->fds.nfds = source+1;
-#else
- if (sptr->ie_next == NULL)
- app->fds.nfds++;
#endif
app->input_count++;
app->rebuild_fdlist = TRUE;