Skip to content

Commit e935b0d

Browse files
committed
Disable the invocation of poll for backends
The internal event handling relied on the poll(2) for monitoring X11 events via I/O multiplexing. However, for backends such as SDL, this manipulation causes problems since the internal file descriptors associated with underlying system events are hidden and not exposed. Thus, we should avoid polling the file descriptors. Instead, let the backend handle the event loop when possible.
1 parent 8ca7e23 commit e935b0d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

backend/sdl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ twin_sdl_t *twin_sdl_create(int width, int height)
133133
tx->screen = twin_screen_create(width, height, _twin_sdl_put_begin,
134134
_twin_sdl_put_span, tx);
135135

136-
twin_set_file(twin_sdl_read_events, SDL_GetWindowDisplayIndex(tx->win),
137-
TWIN_READ, tx);
136+
twin_set_file(twin_sdl_read_events, 0, TWIN_READ, tx);
138137

139138
twin_set_work(twin_sdl_work, TWIN_WORK_REDISPLAY, tx);
140139

@@ -174,7 +173,7 @@ bool twin_sdl_process_events(twin_sdl_t *tx)
174173
bool result;
175174

176175
_twin_run_work();
177-
result = twin_sdl_read_events(SDL_GetWindowDisplayIndex(tx->win), 0, tx);
176+
result = twin_sdl_read_events(0, 0, tx);
178177
_twin_run_work();
179178

180179
return result;

src/file.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66

77
#include <assert.h>
8-
#include <sys/poll.h>
98
#include <unistd.h>
109

10+
#ifdef USE_POLL
11+
#include <sys/poll.h>
12+
#endif
13+
1114
#include "twinint.h"
1215

1316
static twin_queue_t *head;
@@ -31,15 +34,16 @@ int _twin_run_file(twin_time_t delay)
3134
int n;
3235
int i;
3336
int r;
34-
short events;
35-
twin_file_op_t op;
37+
#ifdef USE_POLL
3638
struct pollfd *polls;
39+
#endif
3740

3841
first = (twin_file_t *) _twin_queue_set_order(&head);
3942
if (first) {
4043
for (file = first, n = 0; file;
4144
file = (twin_file_t *) file->queue.order, n++)
4245
;
46+
#ifdef USE_POLL
4347
polls = malloc(n * sizeof(struct pollfd));
4448
if (!polls)
4549
return 1;
@@ -56,20 +60,29 @@ int _twin_run_file(twin_time_t delay)
5660
}
5761
r = poll(polls, n, delay);
5862
if (r > 0)
63+
#endif
5964
for (file = first, i = 0; file;
6065
file = (twin_file_t *) file->queue.order, i++) {
61-
events = polls[i].revents;
66+
twin_file_op_t op = 0;
67+
#ifdef USE_POLL
68+
short events = polls[i].revents;
6269
assert(polls[i].fd == file->file);
63-
op = 0;
6470
if (events & POLLIN)
6571
op |= TWIN_READ;
6672
if (events & POLLOUT)
6773
op |= TWIN_WRITE;
68-
if (op && !(*file->proc)(file->file, op, file->closure))
74+
#endif
75+
if (
76+
#ifdef USE_POLL
77+
op &&
78+
#endif
79+
!(*file->proc)(file->file, op, file->closure))
6980
_twin_queue_delete(&head, &file->queue);
7081
}
7182
_twin_queue_review_order(&first->queue);
83+
#ifdef USE_POLL
7284
free(polls);
85+
#endif
7386
return 1;
7487
} else {
7588
if (delay > 0)

0 commit comments

Comments
 (0)