[1/1] read from connection when polling special events and replies

Submitted by David McFarland on April 19, 2017, 2:58 a.m.

Details

Message ID 20170419025859.32156-2-corngood@gmail.com
State New
Series "read from connection when polling special events and replies"
Headers show

Commit Message

David McFarland April 19, 2017, 2:58 a.m.
Using the mesa vulkan driver, if you acquire an image from a
swapchain using a finite timeout (x11_acquire_next_image_poll_x11),
it will occasionally lock, calling xcb_poll_for_special_event in
a loop until the timeout expires.

Call _xcb_in_read() once from the polling functions for special
events and replies, in the same way as xcb_poll_for_event.

Signed-off-by: David McFarland <corngood@gmail.com>
---
 src/xcb_in.c | 6 ++++++
 1 file changed, 6 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/xcb_in.c b/src/xcb_in.c
index bab4bc7..73209e0 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -661,6 +661,8 @@  int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply,
     assert(reply != 0);
     pthread_mutex_lock(&c->iolock);
     ret = poll_for_reply(c, widen(c, request), reply, error);
+    if(!ret && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
+        ret = poll_for_reply(c, widen(c, request), reply, error);
     pthread_mutex_unlock(&c->iolock);
     return ret;
 }
@@ -678,6 +680,8 @@  int xcb_poll_for_reply64(xcb_connection_t *c, uint64_t request, void **reply, xc
     assert(reply != 0);
     pthread_mutex_lock(&c->iolock);
     ret = poll_for_reply(c, request, reply, error);
+    if(!ret && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
+        ret = poll_for_reply(c, request, reply, error);
     pthread_mutex_unlock(&c->iolock);
     return ret;
 }
@@ -768,6 +772,8 @@  xcb_generic_event_t *xcb_poll_for_special_event(xcb_connection_t *c,
         return 0;
     pthread_mutex_lock(&c->iolock);
     event = get_special_event(c, se);
+    if(!event && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
+        event = get_special_event(c, se);
     pthread_mutex_unlock(&c->iolock);
     return event;
 }

Comments

Uli Schlachter April 29, 2017, 1:14 p.m.
On 19.04.2017 04:58, David McFarland wrote:
> Using the mesa vulkan driver, if you acquire an image from a
> swapchain using a finite timeout (x11_acquire_next_image_poll_x11),
> it will occasionally lock, calling xcb_poll_for_special_event in
> a loop until the timeout expires.
> 
> Call _xcb_in_read() once from the polling functions for special
> events and replies, in the same way as xcb_poll_for_event.
> 
> Signed-off-by: David McFarland <corngood@gmail.com>
> ---
>  src/xcb_in.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/xcb_in.c b/src/xcb_in.c
> index bab4bc7..73209e0 100644
> --- a/src/xcb_in.c
> +++ b/src/xcb_in.c
> @@ -661,6 +661,8 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply,
>      assert(reply != 0);
>      pthread_mutex_lock(&c->iolock);
>      ret = poll_for_reply(c, widen(c, request), reply, error);
> +    if(!ret && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
> +        ret = poll_for_reply(c, widen(c, request), reply, error);
>      pthread_mutex_unlock(&c->iolock);
>      return ret;
>  }
> @@ -678,6 +680,8 @@ int xcb_poll_for_reply64(xcb_connection_t *c, uint64_t request, void **reply, xc
>      assert(reply != 0);
>      pthread_mutex_lock(&c->iolock);
>      ret = poll_for_reply(c, request, reply, error);
> +    if(!ret && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
> +        ret = poll_for_reply(c, request, reply, error);
>      pthread_mutex_unlock(&c->iolock);
>      return ret;
>  }
> @@ -768,6 +772,8 @@ xcb_generic_event_t *xcb_poll_for_special_event(xcb_connection_t *c,
>          return 0;
>      pthread_mutex_lock(&c->iolock);
>      event = get_special_event(c, se);
> +    if(!event && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
> +        event = get_special_event(c, se);
>      pthread_mutex_unlock(&c->iolock);
>      return event;
>  }
> 

Reviewed-by: Uli Schlachter <psychon@znc.in>

(Anyone wants to guess how long it takes for the patch adding the
`_queued`-variant of these function to appear?)
Uli Schlachter May 13, 2017, 7:35 a.m.
On 29.04.2017 15:14, Uli Schlachter wrote:
> On 19.04.2017 04:58, David McFarland wrote:
>> Using the mesa vulkan driver, if you acquire an image from a
>> swapchain using a finite timeout (x11_acquire_next_image_poll_x11),
>> it will occasionally lock, calling xcb_poll_for_special_event in
>> a loop until the timeout expires.
>>
>> Call _xcb_in_read() once from the polling functions for special
>> events and replies, in the same way as xcb_poll_for_event.
>>
>> Signed-off-by: David McFarland <corngood@gmail.com>
>> ---
>>  src/xcb_in.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/src/xcb_in.c b/src/xcb_in.c
>> index bab4bc7..73209e0 100644
>> --- a/src/xcb_in.c
>> +++ b/src/xcb_in.c
>> @@ -661,6 +661,8 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply,
>>      assert(reply != 0);
>>      pthread_mutex_lock(&c->iolock);
>>      ret = poll_for_reply(c, widen(c, request), reply, error);
>> +    if(!ret && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
>> +        ret = poll_for_reply(c, widen(c, request), reply, error);
>>      pthread_mutex_unlock(&c->iolock);
>>      return ret;
>>  }
>> @@ -678,6 +680,8 @@ int xcb_poll_for_reply64(xcb_connection_t *c, uint64_t request, void **reply, xc
>>      assert(reply != 0);
>>      pthread_mutex_lock(&c->iolock);
>>      ret = poll_for_reply(c, request, reply, error);
>> +    if(!ret && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
>> +        ret = poll_for_reply(c, request, reply, error);
>>      pthread_mutex_unlock(&c->iolock);
>>      return ret;
>>  }
>> @@ -768,6 +772,8 @@ xcb_generic_event_t *xcb_poll_for_special_event(xcb_connection_t *c,
>>          return 0;
>>      pthread_mutex_lock(&c->iolock);
>>      event = get_special_event(c, se);
>> +    if(!event && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
>> +        event = get_special_event(c, se);
>>      pthread_mutex_unlock(&c->iolock);
>>      return event;
>>  }
>>
> 
> Reviewed-by: Uli Schlachter <psychon@znc.in>
> 
> (Anyone wants to guess how long it takes for the patch adding the
> `_queued`-variant of these function to appear?)

Pushed to git.