[Freeswitch-svn] [commit] r10684 - in freeswitch/branches/gmaruzz/src: . include mod/endpoints/mod_skypiax

FreeSWITCH SVN gmaruzz at freeswitch.org
Tue Dec 9 11:41:22 PST 2008


Author: gmaruzz
Date: Tue Dec  9 14:41:22 2008
New Revision: 10684

Log:
switch_apr.c: added switch_thread_exit skypiax: less trying to unload without crashes on windows, not yet there

Modified:
   freeswitch/branches/gmaruzz/src/include/switch_apr.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
   freeswitch/branches/gmaruzz/src/switch_apr.c

Modified: freeswitch/branches/gmaruzz/src/include/switch_apr.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/include/switch_apr.h	(original)
+++ freeswitch/branches/gmaruzz/src/include/switch_apr.h	Tue Dec  9 14:41:22 2008
@@ -1321,6 +1321,13 @@
 SWITCH_DECLARE(switch_status_t) switch_file_pipe_timeout_set(switch_file_t *thepipe, switch_interval_time_t timeout);
 
 
+/**
+ * stop the current thread
+ * @param thd The thread to stop
+ * @param retval The return value to pass back to any thread that cares
+ */
+SWITCH_DECLARE(switch_status_t) switch_thread_exit(switch_thread_t *thd, switch_status_t retval);
+
  /** @} */
 
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	Tue Dec  9 14:41:22 2008
@@ -32,6 +32,9 @@
 int running = 1;
 skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
 switch_core_session_t *global_session = NULL;
+#ifdef WIN32
+HANDLE win32_hGlobal_ThreadShutdownEvent;
+#endif /* WIN32 */
 /*************************************************/
 /*************************************************/
 /*************************************************/
@@ -875,11 +878,15 @@
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown)
 {
-  int x = 100;
+  int x = 1000;
   struct skypiax_interface *p = NULL;
 
   running = 0;
 
+#ifdef WIN32
+  SetEvent(win32_hGlobal_ThreadShutdownEvent);
+#endif
+
   while (x) {
 	x--;
     switch_yield(20000);

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	Tue Dec  9 14:41:22 2008
@@ -6,6 +6,9 @@
 extern switch_endpoint_interface_t *skypiax_endpoint_interface;
 extern int running;
 extern skypiax_interface_t SKYPIAX_INTERFACES;
+#ifdef WIN32
+extern HANDLE win32_hGlobal_ThreadShutdownEvent;
+#endif /* WIN32 */
 
 #define SKYPE_AUDIO
 #ifdef SKYPE_AUDIO
@@ -379,7 +382,6 @@
 HWND win32_hInit_MainWindowHandle;
 HINSTANCE win32_hInit_ProcessHandle;
 char win32_acInit_WindowClassName[128];
-HANDLE win32_hGlobal_ThreadShutdownEvent;
 UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
 UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
 HWND win32_hGlobal_SkypeAPIWindowHandle = NULL;
@@ -573,6 +575,7 @@
   /*  destroy window class */
 
   struct skypiax_interface *p;
+  DWORD MsgWaitResult;
   p = obj;
 
   switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0],
@@ -590,25 +593,35 @@
       && win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
     if (win32_Initialize_CreateWindowClass()) {
       if (win32_Initialize_CreateMainWindow()) {
-        win32_hGlobal_ThreadShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+        //win32_hGlobal_ThreadShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+        win32_hGlobal_ThreadShutdownEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
         if (win32_hGlobal_ThreadShutdownEvent != NULL) {
           if (SendMessage
               (HWND_BROADCAST, win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
                (WPARAM) win32_hInit_MainWindowHandle, 0) != 0) {
             win32_AsteriskHandlesSkype->win32_hInit_MainWindowHandle =
               win32_hInit_MainWindowHandle;
-            while (1) {
-              MSG oMessage;
-	  if(!running)
-		  break;
-
-              while (GetMessage(&oMessage, 0, 0, 0) != FALSE) {
-	  if(!running)
-		  break;
-                TranslateMessage(&oMessage);
-                DispatchMessage(&oMessage);
-              }
-            }
+	    while (1) {
+		    MSG oMessage;
+		    const HANDLE *MsgWaitHandles[1];
+
+		    MsgWaitHandles[0] = &win32_hGlobal_ThreadShutdownEvent;
+		    if(!running)
+			    break;
+		    while (MsgWaitResult = MsgWaitForMultipleObjects(1,MsgWaitHandles, FALSE, 300,QS_ALLPOSTMESSAGE)){
+			    if(!running)
+				    break;
+			    if (MsgWaitResult == WAIT_TIMEOUT) {
+				    continue;
+			    }
+
+			    GetMessage(&oMessage, 0, 0, 0);
+			    if(!running)
+				    break;
+			    TranslateMessage(&oMessage);
+			    DispatchMessage(&oMessage);
+		    }
+	    }
           }
           CloseHandle(win32_hGlobal_ThreadShutdownEvent);
         }
@@ -617,6 +630,10 @@
       win32_DeInitialize_DestroyWindowClass();
     }
   }
+
+
+  switch_thread_exit(thread, SWITCH_STATUS_SUCCESS);
+
   return NULL;
 }
 

Modified: freeswitch/branches/gmaruzz/src/switch_apr.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/switch_apr.c	(original)
+++ freeswitch/branches/gmaruzz/src/switch_apr.c	Tue Dec  9 14:41:22 2008
@@ -970,6 +970,17 @@
 }
 
 
+/**
+ * stop the current thread
+ * @param thd The thread to stop
+ * @param retval The return value to pass back to any thread that cares
+ */
+SWITCH_DECLARE(switch_status_t) switch_thread_exit(switch_thread_t *thd, switch_status_t retval)
+{
+	return apr_thread_exit((apr_thread_t *)thd, retval);
+}
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c



More information about the Freeswitch-svn mailing list