[gnome-remote-desktop] rdp-fuse-clipboard: Turn WinPR events into GrdSyncPoints



commit 126446195b00a841a362789416a1b4aad881cd8b
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Sat Jul 23 16:09:53 2022 +0200

    rdp-fuse-clipboard: Turn WinPR events into GrdSyncPoints
    
    Recently, it was discovered, that WinPR events are handled in
    unexpected manners on a few systems.
    To avoid unexpected behaviour, reduce their usage, wherever it is
    possible.

 src/grd-rdp-fuse-clipboard.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/src/grd-rdp-fuse-clipboard.c b/src/grd-rdp-fuse-clipboard.c
index c295096f..5c99bb0d 100644
--- a/src/grd-rdp-fuse-clipboard.c
+++ b/src/grd-rdp-fuse-clipboard.c
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #include "grd-clipboard-rdp.h"
+#include "grd-utils.h"
 
 #define CLIP_DATA_ENTRY_DROP_TIMEOUT_MS (60 * 1000)
 #define CLIP_DATA_ENTRY_DROP_TIMEOUT_DELTA_US (10 * G_USEC_PER_SEC)
@@ -123,8 +124,8 @@ struct _GrdRdpFuseClipboard
 
   GThread *fuse_thread;
   struct fuse_session *fuse_handle;
-  HANDLE start_event;
-  HANDLE stop_event;
+  GrdSyncPoint sync_point_start;
+  GrdSyncPoint sync_point_stop;
 
   GSource *timeout_reset_source;
   GHashTable *timeouts_to_reset;
@@ -1331,7 +1332,7 @@ fuse_thread_func (gpointer data)
 
   fuse_daemonize (1);
 
-  SetEvent (rdp_fuse_clipboard->start_event);
+  grd_sync_point_complete (&rdp_fuse_clipboard->sync_point_start, TRUE);
 
   g_debug ("[FUSE Clipboard] Starting FUSE session");
   result = fuse_session_loop (rdp_fuse_clipboard->fuse_handle);
@@ -1341,7 +1342,7 @@ fuse_thread_func (gpointer data)
   g_debug ("[FUSE Clipboard] Unmounting FUSE filesystem");
   fuse_session_unmount (rdp_fuse_clipboard->fuse_handle);
 
-  WaitForSingleObject (rdp_fuse_clipboard->stop_event, INFINITE);
+  grd_sync_point_wait_for_completion (&rdp_fuse_clipboard->sync_point_stop);
   g_clear_pointer (&rdp_fuse_clipboard->fuse_handle, fuse_session_destroy);
 
   return NULL;
@@ -1357,16 +1358,13 @@ grd_rdp_fuse_clipboard_new (GrdClipboardRdp *clipboard_rdp,
   rdp_fuse_clipboard->clipboard_rdp = clipboard_rdp;
   rdp_fuse_clipboard->mount_path = g_strdup (mount_path);
 
-  rdp_fuse_clipboard->start_event = CreateEvent (NULL, TRUE, FALSE, NULL);
-  rdp_fuse_clipboard->stop_event = CreateEvent (NULL, TRUE, FALSE, NULL);
   rdp_fuse_clipboard->fuse_thread = g_thread_new ("RDP FUSE clipboard thread",
                                                   fuse_thread_func,
                                                   rdp_fuse_clipboard);
   if (!rdp_fuse_clipboard->fuse_thread)
     g_error ("[FUSE Clipboard] Failed to create FUSE thread");
 
-  WaitForSingleObject (rdp_fuse_clipboard->start_event, INFINITE);
-  g_clear_pointer (&rdp_fuse_clipboard->start_event, CloseHandle);
+  grd_sync_point_wait_for_completion (&rdp_fuse_clipboard->sync_point_start);
 
   return rdp_fuse_clipboard;
 }
@@ -1401,14 +1399,13 @@ grd_rdp_fuse_clipboard_dispose (GObject *object)
       struct stat attr;
 
       g_assert (rdp_fuse_clipboard->fuse_handle);
-      g_assert (!rdp_fuse_clipboard->start_event);
 
       clear_all_selections (rdp_fuse_clipboard);
 
       g_debug ("[FUSE Clipboard] Stopping FUSE thread");
       fuse_session_exit (rdp_fuse_clipboard->fuse_handle);
       dismiss_all_requests (rdp_fuse_clipboard);
-      SetEvent (rdp_fuse_clipboard->stop_event);
+      grd_sync_point_complete (&rdp_fuse_clipboard->sync_point_stop, TRUE);
 
       /**
        * FUSE does not immediately stop the session after fuse_session_exit() has
@@ -1423,7 +1420,6 @@ grd_rdp_fuse_clipboard_dispose (GObject *object)
       g_debug ("[FUSE Clipboard] Waiting on FUSE thread");
       g_clear_pointer (&rdp_fuse_clipboard->fuse_thread, g_thread_join);
       g_debug ("[FUSE Clipboard] FUSE thread stopped");
-      g_clear_pointer (&rdp_fuse_clipboard->stop_event, CloseHandle);
     }
 
   g_clear_pointer (&rdp_fuse_clipboard->mount_path, g_free);
@@ -1446,6 +1442,9 @@ grd_rdp_fuse_clipboard_finalize (GObject *object)
 {
   GrdRdpFuseClipboard *rdp_fuse_clipboard = GRD_RDP_FUSE_CLIPBOARD (object);
 
+  grd_sync_point_clear (&rdp_fuse_clipboard->sync_point_stop);
+  grd_sync_point_clear (&rdp_fuse_clipboard->sync_point_start);
+
   g_mutex_clear (&rdp_fuse_clipboard->selection_mutex);
   g_mutex_clear (&rdp_fuse_clipboard->filesystem_mutex);
 
@@ -1555,6 +1554,9 @@ grd_rdp_fuse_clipboard_init (GrdRdpFuseClipboard *rdp_fuse_clipboard)
   g_mutex_init (&rdp_fuse_clipboard->filesystem_mutex);
   g_mutex_init (&rdp_fuse_clipboard->selection_mutex);
 
+  grd_sync_point_init (&rdp_fuse_clipboard->sync_point_start);
+  grd_sync_point_init (&rdp_fuse_clipboard->sync_point_stop);
+
   timeout_reset_source = g_source_new (&timeout_reset_source_funcs,
                                        sizeof (GSource));
   g_source_set_callback (timeout_reset_source, reset_clip_data_entry_timeouts,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]