[Spice-commits] vdagent/vdagent.cpp

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jul 5 13:27:02 UTC 2018


 vdagent/vdagent.cpp |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

New commits:
commit 6a0683707f3fcebcca3d3e5aced46ec3024f3784
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sat Jun 30 05:31:13 2018 +0100

    Allocate _control_event and _stop_event just once
    
    Handle _control_event and _stop_event destruction in destructor.
    Allows to call VDAgent::run multiple time if needed.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index 1a68e0c..64055c4 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -224,6 +224,8 @@ VDAgent::VDAgent()
 
 VDAgent::~VDAgent()
 {
+    CloseHandle(_stop_event);
+    CloseHandle(_control_event);
     delete _log;
 }
 
@@ -285,13 +287,18 @@ bool VDAgent::run()
             return false;
         }
     }
-    _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
+    if (!_control_event)
+        _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
     if (!_control_event) {
         vd_printf("CreateEvent() failed: %lu", GetLastError());
         cleanup();
         return false;
     }
-    _stop_event = OpenEvent(SYNCHRONIZE, FALSE, VD_AGENT_STOP_EVENT);
+    ResetEvent(_control_event);
+
+    if (!_stop_event)
+        _stop_event = OpenEvent(SYNCHRONIZE, FALSE, VD_AGENT_STOP_EVENT);
+
     memset(&wcls, 0, sizeof(wcls));
     wcls.lpfnWndProc = &VDAgent::wnd_proc;
     wcls.lpszClassName = VD_AGENT_WINCLASS_NAME;
@@ -339,8 +346,6 @@ bool VDAgent::run()
 void VDAgent::cleanup()
 {
     FreeLibrary(_user_lib);
-    CloseHandle(_stop_event);
-    CloseHandle(_control_event);
     CloseHandle(_vio_serial);
 }
 


More information about the Spice-commits mailing list