[pan2: 190/268] fixed locking



commit 22acb9c0e2cf412071eee0a5ffbd001d1856caeb
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Wed Nov 9 10:43:28 2011 +0100

    fixed locking

 pan.cbp                       |    1 +
 pan/data-impl/Makefile.am     |    2 +-
 pan/general/Makefile.am       |    5 +++--
 pan/general/worker-pool.cc    |    1 +
 pan/gui/body-pane.cc          |    1 +
 pan/gui/group-pane.cc         |    1 +
 pan/gui/gui.cc                |   35 ++++++++++++++++++-----------------
 pan/gui/gui.h                 |    1 +
 pan/gui/header-pane.cc        |    1 +
 pan/gui/pan.cc                |   14 +++++++++-----
 pan/tasks/Makefile.am         |    2 +-
 pan/tasks/socket-impl-main.cc |   26 ++++++++++++++++----------
 12 files changed, 54 insertions(+), 36 deletions(-)
---
diff --git a/pan.cbp b/pan.cbp
index 300777c..84703dc 100644
--- a/pan.cbp
+++ b/pan.cbp
@@ -85,6 +85,7 @@
 		<Unit filename="pan/general/e-util.h" />
 		<Unit filename="pan/general/file-util.cc" />
 		<Unit filename="pan/general/file-util.h" />
+		<Unit filename="pan/general/gdk-threads.h" />
 		<Unit filename="pan/general/line-reader.cc" />
 		<Unit filename="pan/general/line-reader.h" />
 		<Unit filename="pan/general/locking.h" />
diff --git a/pan/data-impl/Makefile.am b/pan/data-impl/Makefile.am
index c20532d..deffd2b 100644
--- a/pan/data-impl/Makefile.am
+++ b/pan/data-impl/Makefile.am
@@ -39,7 +39,7 @@ TEST_LDADD = \
  ../data/libdata.a \
  ../usenet-utils/libusenetutils.a \
  ../general/libgeneralutils.a \
- ../../uulib/libuu.a @GMIME_LIBS@ @GLIB_LIBS@ @OPENSSL_LIBS@
+ ../../uulib/libuu.a @GMIME_LIBS@ @GLIB_LIBS@ @OPENSSL_LIBS@ @GTK_LIBS@
 add_server_SOURCES = add-server.cc
 add_server_LDADD = $(TEST_LDADD)
 headers_test_SOURCES = headers-test.cc
diff --git a/pan/general/Makefile.am b/pan/general/Makefile.am
index a6a02e4..edf7a2f 100644
--- a/pan/general/Makefile.am
+++ b/pan/general/Makefile.am
@@ -1,4 +1,5 @@
-AM_CPPFLAGS = -I top_srcdir@ @GMIME_CFLAGS@ @GLIB_CFLAGS@
+AM_CPPFLAGS = -I top_srcdir@ @GMIME_CFLAGS@ @GLIB_CFLAGS@ @GTK_CFLAGS@
+AM_LDFLAGS = @GTK_LIBS@
 
 noinst_LIBRARIES = libgeneralutils.a
 
@@ -34,7 +35,7 @@ noinst_HEADERS = \
  text-match.h \
  time-elapsed.h \
  utf8-utils.h \
- worker-pool.h 
+ worker-pool.h
 
 #noinst_PROGRAMS = \
 #  progress-test \
diff --git a/pan/general/worker-pool.cc b/pan/general/worker-pool.cc
index 6ff4b76..ec96e60 100644
--- a/pan/general/worker-pool.cc
+++ b/pan/general/worker-pool.cc
@@ -22,6 +22,7 @@
  */
 #include <cassert>
 #include <glib/gmain.h> // for g_idle_add
+#include <gdk/gdk.h>
 #include <pan/general/debug.h>
 #include <pan/general/macros.h>
 #include "worker-pool.h"
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index 7936e46..b87e13b 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -30,6 +30,7 @@ extern "C" {
 }
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <pan/general/debug.h>
+//#include <pan/general/gdk-threads.h>
 #include <pan/general/log.h>
 #include <pan/general/macros.h>
 #include <pan/general/utf8-utils.h>
diff --git a/pan/gui/group-pane.cc b/pan/gui/group-pane.cc
index 7cbbe59..f3ab501 100644
--- a/pan/gui/group-pane.cc
+++ b/pan/gui/group-pane.cc
@@ -25,6 +25,7 @@ extern "C" {
   #include <gtk/gtk.h>
 }
 #include <pan/general/debug.h>
+//#include <pan/general/gdk-threads.h>
 #include <pan/general/log.h>
 #include <pan/general/macros.h>
 #include <pan/general/quark.h>
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 3eaa121..1749ac7 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -411,8 +411,8 @@ GUI :: watch_cursor_on ()
   GdkCursor * cursor = gdk_cursor_new (GDK_WATCH);
   gdk_window_set_cursor ( gtk_widget_get_window(_root), cursor);
   gdk_cursor_unref (cursor);
-  while (gtk_events_pending ())
-    gtk_main_iteration ();
+//  while (gtk_events_pending ())
+//    gtk_main_iteration ();
 }
 
 void
@@ -1307,23 +1307,24 @@ bool GUI::deletion_confirmation_dialog()
 bool GUI :: confirm_accept_new_cert_dialog(GtkWindow * parent, X509* cert, const Quark& server)
 {
   bool ret(false);
-  gdk_threads_enter();
-  GtkWidget * d = gtk_message_dialog_new (
-    parent,
-    GtkDialogFlags(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
-    GTK_MESSAGE_WARNING,
-    GTK_BUTTONS_NONE, NULL);
   char buf[4096];
   CertStore::pretty_print_x509(buf,sizeof(buf), server, cert);
-  HIG :: message_dialog_set_text (GTK_MESSAGE_DIALOG(d), buf,
-    _("Do you want to accept it permanently (deletable afterwards) ?"));
-  gtk_dialog_add_buttons (GTK_DIALOG(d),
-                          GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
-                          GTK_STOCK_APPLY, GTK_RESPONSE_YES,
-                          NULL);
-  gtk_dialog_set_default_response (GTK_DIALOG(d), GTK_RESPONSE_NO);
-  ret = gtk_dialog_run (GTK_DIALOG(d)) == GTK_RESPONSE_YES;
-  gtk_widget_destroy(d);
+  gdk_threads_enter();
+    GtkWidget * d = gtk_message_dialog_new (
+      parent,
+      GtkDialogFlags(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
+      GTK_MESSAGE_WARNING,
+      GTK_BUTTONS_NONE, NULL);
+
+    HIG :: message_dialog_set_text (GTK_MESSAGE_DIALOG(d), buf,
+      _("Do you want to accept it permanently (deletable afterwards) ?"));
+    gtk_dialog_add_buttons (GTK_DIALOG(d),
+                            GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
+                            GTK_STOCK_APPLY, GTK_RESPONSE_YES,
+                            NULL);
+    gtk_dialog_set_default_response (GTK_DIALOG(d), GTK_RESPONSE_NO);
+    ret = gtk_dialog_run (GTK_DIALOG(d)) == GTK_RESPONSE_YES;
+    gtk_widget_destroy(d);
   gdk_threads_leave();
   return ret;
 }
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index 3889724..b2a39af 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -20,6 +20,7 @@
 #define _Pan_h_
 
 #include <pan/general/log.h>
+#include <pan/general/locking.h>
 #include <pan/general/progress.h>
 #include <pan/data/article-cache.h>
 #include <pan/data/encode-cache.h>
diff --git a/pan/gui/header-pane.cc b/pan/gui/header-pane.cc
index ab76800..a74ff4f 100644
--- a/pan/gui/header-pane.cc
+++ b/pan/gui/header-pane.cc
@@ -26,6 +26,7 @@ extern "C" {
 #include <cmath>
 #include <algorithm>
 #include <pan/general/debug.h>
+//#include <pan/general/gdk-threads.h>
 #include <pan/general/e-util.h>
 #include <pan/general/log.h>
 #include <pan/general/macros.h>
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index d2debbd..6ef0a2e 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -65,15 +65,19 @@ namespace
 
   void mainloop ()
   {
-#if 1
+//#if 1
     if (nongui_gmainloop)
       g_main_loop_run (nongui_gmainloop);
     else
+    {
+      gdk_threads_enter();
       gtk_main ();
-#else
-    while (gtk_events_pending ())
-      gtk_main_iteration ();
-#endif
+      gdk_threads_leave();
+    }
+//#else
+//    while (gtk_events_pending ())
+//      gtk_main_iteration ();
+//#endif
   }
 
   void mainloop_quit ()
diff --git a/pan/tasks/Makefile.am b/pan/tasks/Makefile.am
index 9264efb..3e39bb4 100644
--- a/pan/tasks/Makefile.am
+++ b/pan/tasks/Makefile.am
@@ -1,6 +1,6 @@
 AM_CPPFLAGS = -I top_srcdir@ @GMIME_CFLAGS@ @GLIB_CFLAGS@ @OPENSSL_CFLAGS@
 
-AM_LDFLAGS = ../../uulib/libuu.a -lz @OPENSSL_LIBS@
+AM_LDFLAGS = ../../uulib/libuu.a @OPENSSL_LIBS@
 
 noinst_LIBRARIES = libtasks.a
 
diff --git a/pan/tasks/socket-impl-main.cc b/pan/tasks/socket-impl-main.cc
index afb0913..7c64b0b 100644
--- a/pan/tasks/socket-impl-main.cc
+++ b/pan/tasks/socket-impl-main.cc
@@ -35,6 +35,7 @@
 #include <cstring>
 
 #include <pan/general/log.h>
+#include <pan/general/locking.h>
 #include <pan/general/macros.h>
 #include <pan/general/worker-pool.h>
 #include <pan/general/string-view.h>
@@ -94,30 +95,35 @@ namespace pan
 #ifdef HAVE_OPENSSL
 namespace
 {
-  static pthread_mutex_t *lock_cs=0;
+//  static pthread_mutex_t *lock_cs=0;
+  static Mutex* mutex;
 
   void gio_lock(int mode, int type, const char *file, int line)
   {
     if (mode & CRYPTO_LOCK)
-      pthread_mutex_lock(&(lock_cs[type]));
+      mutex[type].lock();
+//      pthread_mutex_lock(&(lock_cs[type]));
     else
-      pthread_mutex_unlock(&(lock_cs[type]));
+      mutex[type].unlock();
+//      pthread_mutex_unlock(&(lock_cs[type]));
   }
 
   void ssl_thread_setup() {
-    lock_cs = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
-    for (int i=0; i<CRYPTO_num_locks(); i++)
-      if (pthread_mutex_init(&lock_cs[i],0) != 0)
-        g_warning("error initialing mutex!");
+    mutex = new Mutex[CRYPTO_num_locks()];
+//    lock_cs = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
+//    for (int i=0; i<CRYPTO_num_locks(); i++)
+//      if (pthread_mutex_init(&lock_cs[i],0) != 0)
+//        g_warning("error initialing mutex!");
 
     CRYPTO_set_locking_callback(gio_lock);
   }
 
   void ssl_thread_cleanup() {
-    for (int i=0; i<CRYPTO_num_locks(); i++)
-      pthread_mutex_destroy(&lock_cs[i]);
+//    for (int i=0; i<CRYPTO_num_locks(); i++)
+//      pthread_mutex_destroy(&lock_cs[i]);
+    delete [] mutex;
     CRYPTO_set_locking_callback(0);
-    OPENSSL_free(lock_cs);
+//    OPENSSL_free(lock_cs);
   }
 
 }



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