Ethereal-dev: [Ethereal-dev] USE_THREADS on Win32

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Gisle Vanem" <giva@xxxxxxxxx>
Date: Thu, 24 Jun 2004 15:14:10 +0200
Seems my message of yesterday got sent to /dev/null.
So here's a repost.

As of GLib/GTK 2.4 (I think it was) using threads seems to
work fine. I've built Pan, the news-reader with this. The ethereal UI 
update works smoother with update_thread() than with the
update_cb() timer callback (3 sec is a long time!).

So Windows should also have the option to call g_thread_init()
if USE_THREADS is defined.

Also, in webbrowser.c I've included <shellapi.h> directly since
it isn't included if WIN32_LEAN_AND_MEAN is defined (a lot
fast to built with this on).

--gv
--- ethereal-2004-06-23/gtk/main.c	Mon Jun 21 18:45:07 2004
+++ gtk/main.c	Wed Jun 23 16:40:24 2004
@@ -146,6 +146,18 @@
 #define DEF_READY_MESSAGE " Ready to load file"
 #endif

+#if defined(USE_THREADS)
+# ifdef WIN32 && (GTK_MAJOR_VERSION < 2 || (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION < 4)
+   /* Win32 requires GTK 2.4.x for UI update */
+#  undef USE_THREADS   /* Maybe an "#error"? */
+# elif (GTK_MAJOR_VERSION < 2)
+   /* Others requires GTK 2.x for UI update */
+#  undef USE_THREADS
+# endif
+#elif !defined(G_THREADS_ENABLED)
+# undef USE_THREADS
+#endif
+
 capture_file cfile;
 GtkWidget   *main_display_filter_widget=NULL;
 GtkWidget   *top_level = NULL, *tree_view, *byte_nb_ptr, *tv_scrollw;
@@ -1126,7 +1138,7 @@
 }
 #endif

-#if defined WIN32 || GTK_MAJOR_VERSION < 2 || ! defined USE_THREADS
+#if !defined USE_THREADS
 /*
    Once every 3 seconds we get a callback here which we use to update
    the tap extensions. Since Gtk1 is single threaded we dont have to
@@ -1148,7 +1160,7 @@
    gtk1-ethereal and it will just work.
  */
 static GStaticMutex update_thread_mutex = G_STATIC_MUTEX_INIT;
-gpointer
+static gpointer
 update_thread(gpointer data _U_)
 {
     while(1){
@@ -1170,17 +1182,19 @@
     return NULL;
 }
 #endif
+
 void
 protect_thread_critical_region(void)
 {
-#if ! defined WIN32 && GTK_MAJOR_VERSION >= 2 && defined USE_THREADS
+#ifdef USE_THREADS
     g_static_mutex_lock(&update_thread_mutex);
 #endif
 }
+
 void
 unprotect_thread_critical_region(void)
 {
-#if ! defined WIN32 && GTK_MAJOR_VERSION >= 2 && defined USE_THREADS
+#ifdef USE_THREADS
     g_static_mutex_unlock(&update_thread_mutex);
 #endif
 }
@@ -1655,8 +1669,7 @@
     exit(0);
   }

-  /* multithread support currently doesn't seem to work in win32 gtk2.0.6 */
-#if ! defined WIN32 && GTK_MAJOR_VERSION >= 2 && defined G_THREADS_ENABLED && defined USE_THREADS
+#ifdef USE_THREADS
   {
       GThread *ut;
       g_thread_init(NULL);
@@ -1664,10 +1677,10 @@
       ut=g_thread_create(update_thread, NULL, FALSE, NULL);
       g_thread_set_priority(ut, G_THREAD_PRIORITY_LOW);
   }
-#else  /* WIN32 || GTK1.2 || !G_THREADS_ENABLED || !USE_THREADS */
+#else  /* !USE_THREADS */
   /* this is to keep tap extensions updating once every 3 seconds */
   gtk_timeout_add(3000, (GtkFunction)update_cb,(gpointer)NULL);
-#endif /* !WIN32 && GTK2 && G_THREADS_ENABLED */
+#endif /* USE_THREADS */

 #if HAVE_GNU_ADNS
   gtk_timeout_add(750, (GtkFunction) host_name_lookup_process, NULL);
--- ethereal-2004-06-23/gtk/webbrowser.c	Wed Jun 23 03:38:39 2004
+++ gtk/webbrowser.c	Wed Jun 23 15:37:45 2004
@@ -39,6 +39,7 @@
 #if defined(G_OS_WIN32)
 /* Win32 - use Windows shell services to start a browser */
 #include <windows.h>
+#include <shellapi.h>
 #elif defined (HAVE_OS_X_FRAMEWORKS)
 /* Mac OS X - use Launch Services to start a browser */
 #include <CoreFoundation/CFBase.h>