Skip to content
Snippets Groups Projects

WIP: xcb_wait_for_special_event_with_timeout()

6 unresolved threads

This surely has portability problems and is ugly since it works with three different representations (timeout in milliseconds, deadline as timeval, deadline as timespec).

Also, this is completely untested. But at least its a start.

Related to #38

Anyone who wants is free to pick this up and do it properly.

For the public API, I was thinking on whether this should be a timeout (as it is now) or a deadline (struct timeval / timespec). I only picked the timeout so that no structs from sys/time.h appear in the public API. No idea if that was a good choice.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
477 489 pthread_mutex_unlock(&c->iolock);
478 490 do {
479 491 #if USE_POLL
480 ret = poll(&fd, 1, -1);
492 int timeout = -1;
493 if(deadline && now) {
494 struct timeval diff;
495 timersub(deadline, now, &diff);
496 timeout = now->tv_sec * 1000 + now->tv_usec / 1000;
  • 37 37 #include <fcntl.h>
    38 38 #include <errno.h>
    39 39 #include <limits.h>
    40 #include <sys/time.h> /* I bet this does not work on Windows... */
  • 445 451 /* If the thing I should be doing is already being done, wait for it. */
    446 452 if(count ? c->out.writing : c->in.reading)
    447 453 {
    448 pthread_cond_wait(cond, &c->iolock);
    454 if(deadline) {
    455 struct timespec spec;
    456 spec.tv_sec = deadline->tv_sec;
    457 spec.tv_nsec = deadline->tv_usec * 100;
  • 793 timeout.tv_sec = millisecs_timeout / 1000;
    794 timeout.tv_usec = (millisecs_timeout % 1000) * 1000;
    795 gettimeofday(&now, NULL); // TODO: Check for errors?
    796 timeradd(&now, &timeout, &deadline);
    797
    798 pthread_mutex_lock(&c->iolock);
    799
    800 insert_special(&c->in.special_waiters, &special, se);
    801
    802 /* get_special_event returns 0 on empty list. */
    803 while(!(event = get_special_event(c, se))) {
    804 if(timercmp(&deadline, &now, <))
    805 break;
    806 if(!_xcb_conn_timedwait(c, &se->special_event_cond, 0, 0, &now, &deadline))
    807 break;
    808 gettimeofday(&now, NULL); // TODO: Check for errors?
  • 486 504 break;
    487 505 }
    488 506 #else
    489 ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
    507 struct timeval diff;
    508 struct timeval *timeout = NULL;
    509 if(deadline && now) {
    510 timersub(deadline, now, &diff);
    511 timeout = &diff;
    512 }
    513 ret = select(c->fd + 1, &rfds, &wfds, 0, timeout);
    490 514 #endif
    491 515 } while (ret == -1 && errno == EINTR);
  • Thanks for working on this!

    It's more complicated than I thought it would be; for some reason, I thought there were already similar XCB APIs taking a timeout.

    Anyway, apart from the issues I noticed, it looks like it might work (except on Windows). :)

  • mentioned in merge request mesa/mesa!13564 (merged)

  • mentioned in merge request mesa/mesa!17742 (closed)

  • mentioned in merge request mesa/mesa!19279 (merged)

  • Please register or sign in to reply
    Loading