client: Add new API to handle pending events 54/303454/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Fri, 2 Jun 2023 03:52:14 +0000 (12:52 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Thu, 28 Dec 2023 03:40:59 +0000 (12:40 +0900)
 - If the FD is obtained through tdm_client_get_fd() and
 the client POLL the fd directly, the events in the default queue
 may not be processed if the wl_display_roundtrip_queue() is called.

 1. client get fd and poll
 2. client call tdm_client_output_create_vblank()
  <- 3. display server send event (default queue)
 4. wl_display_roundtrip_queue() is called inside
   tdm_client_output_create_vblank() (private queue)
   4.1. read_events/queue_events done
   4.2. dispatch events only in private queue
 5. client locked up because vblank event in default queue
   cannot be processed.

 - This problem can be solved by providing a new API that
  allows to handle the pending events in default queue.

Change-Id: Ife737cf43edd5aa9d4c0cc464cc9f88bb69840a1
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
client/tdm_client.c
client/tdm_client.h

index f322a49..caaa66f 100644 (file)
@@ -639,6 +639,34 @@ tdm_client_handle_events(tdm_client *client)
        /* LCOV_EXCL_STOP */
 }
 
+tdm_error
+tdm_client_handle_pending_events(tdm_client *client)
+{
+       tdm_private_client *private_client;
+
+       TDM_RETURN_VAL_IF_FAIL(client != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+       /* LCOV_EXCL_START */
+       private_client = (tdm_private_client*)client;
+
+       pthread_mutex_lock(&private_client->lock);
+
+       if (CHECK_WL_PROTOCOL_ERROR(private_client)) {
+               pthread_mutex_unlock(&private_client->lock);
+               return TDM_ERROR_PROTOCOL_ERROR;
+       }
+
+       if (wl_display_dispatch_pending(private_client->display) < 0 ) {
+               pthread_mutex_unlock(&private_client->lock);
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       pthread_mutex_unlock(&private_client->lock);
+
+       return TDM_ERROR_NONE;
+       /* LCOV_EXCL_STOP */
+}
+
 static int
 _tdm_client_poll(struct wl_display *display, short int events, int timeout)
 {
index 7f5d247..92dd6bf 100644 (file)
@@ -129,6 +129,15 @@ tdm_error
 tdm_client_handle_events_timeout(tdm_client *client, int ms_timeout);
 
 /**
+ * @brief Handle the pending events of the given tdm_client
+ * @param[in] client A TDM client object
+ * @return #TDM_ERROR_NONE if success. Otherwise, error value.
+ * @see #tdm_client_get_fd
+ */
+tdm_error
+tdm_client_handle_pending_events(tdm_client *client);
+
+/**
  * @brief @b Deprecated. Wait for VBLANK.
  * @deprecated
  * @details After interval vblanks, a client vblank handler will be called.