[balsa/gtk3] Make changes in previous commit conditional



commit ebb1e846e13b3071dd27437b707ccef8de3435a6
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Jun 5 18:06:06 2012 -0400

    Make changes in previous commit conditional
    
    	* libbalsa/imap-server.c (libbalsa_imap_server_init),
    	(libbalsa_imap_server_finalize): make previous changes
    	conditional on glib version at least 2.32.
    	* libbalsa/libbalsa-conf.c (lbc_lock), (lbc_unlock): ditto.
    	* libbalsa/mime-stream-shared.c (lbmss_stream_class_init),
    	(libbalsa_mime_stream_shared_lock),
    	(libbalsa_mime_stream_shared_unlock): ditto.

 ChangeLog                     |   13 +++++++++++++
 libbalsa/imap-server.c        |   18 ++++++++++++++++++
 libbalsa/libbalsa-conf.c      |   12 ++++++++++++
 libbalsa/mime-stream-shared.c |   25 +++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ffffc55..ee828d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2012-06-05  Peter Bloomfield
 
+	Make changes in previous commit conditional on glib version
+	at least 2.32.
+
+	* libbalsa/imap-server.c (libbalsa_imap_server_init),
+	(libbalsa_imap_server_finalize): make previous changes
+	conditional.
+	* libbalsa/libbalsa-conf.c (lbc_lock), (lbc_unlock): ditto.
+	* libbalsa/mime-stream-shared.c (lbmss_stream_class_init),
+	(libbalsa_mime_stream_shared_lock),
+	(libbalsa_mime_stream_shared_unlock): ditto.
+
+2012-06-05  Peter Bloomfield
+
 	Deprecation cleanup; fixes bgo #677381
 
 	* libbalsa/imap-server.c (libbalsa_imap_server_init),
diff --git a/libbalsa/imap-server.c b/libbalsa/imap-server.c
index 4fe03fa..cd31e5b 100644
--- a/libbalsa/imap-server.c
+++ b/libbalsa/imap-server.c
@@ -65,7 +65,11 @@ struct LibBalsaImapServer_ {
     gboolean offline_mode;
     
 #if defined(BALSA_USE_THREADS)
+#if GLIB_CHECK_VERSION(2, 32, 0)
     GMutex lock; /* protects the following members */
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+    GMutex *lock; /* protects the following members */
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 #endif
     guint used_connections;
     GList *used_handles;
@@ -102,9 +106,15 @@ static gboolean connection_cleanup(gpointer ptr);
 static pthread_mutex_t imap_servers_lock = PTHREAD_MUTEX_INITIALIZER;
 #define LOCK_SERVERS()   pthread_mutex_lock(&imap_servers_lock)
 #define UNLOCK_SERVERS() pthread_mutex_unlock(&imap_servers_lock)
+#if GLIB_CHECK_VERSION(2, 32, 0)
 #define LOCK_SERVER(server)    g_mutex_lock(&((server)->lock))
 #define TRYLOCK_SERVER(server) g_mutex_trylock(&((server)->lock))
 #define UNLOCK_SERVER(server)  g_mutex_unlock(&((server)->lock))
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+#define LOCK_SERVER(server)    g_mutex_lock(((server)->lock))
+#define TRYLOCK_SERVER(server) g_mutex_trylock(((server)->lock))
+#define UNLOCK_SERVER(server)  g_mutex_unlock(((server)->lock))
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 #else
 #define LOCK_SERVERS()
 #define UNLOCK_SERVERS()
@@ -212,7 +222,11 @@ libbalsa_imap_server_init(LibBalsaImapServer * imap_server)
     LIBBALSA_SERVER(imap_server)->protocol = "imap";
     imap_server->key = NULL;
 #if defined(BALSA_USE_THREADS)
+#if GLIB_CHECK_VERSION(2, 32, 0)
     g_mutex_init(&imap_server->lock);
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+    imap_server->lock = g_mutex_new();
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 #endif
     imap_server->max_connections = MAX_CONNECTIONS_PER_SERVER;
     imap_server->used_connections = 0;
@@ -250,7 +264,11 @@ libbalsa_imap_server_finalize(GObject * object)
 #endif
     libbalsa_imap_server_force_disconnect(imap_server);
 #if defined(BALSA_USE_THREADS)
+#if GLIB_CHECK_VERSION(2, 32, 0)
     g_mutex_clear(&imap_server->lock);
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+    g_mutex_free(imap_server->lock);
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 #endif
     g_free(imap_server->key); imap_server->key = NULL;
 
diff --git a/libbalsa/libbalsa-conf.c b/libbalsa/libbalsa-conf.c
index e0d8147..bf6a51e 100644
--- a/libbalsa/libbalsa-conf.c
+++ b/libbalsa/libbalsa-conf.c
@@ -147,12 +147,20 @@ lbc_init(LibBalsaConf * conf, const gchar * filename,
 }
 
 #ifdef BALSA_USE_THREADS
+#if GLIB_CHECK_VERSION(2, 32, 0)
 static GRecMutex lbc_mutex;
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+static GStaticRecMutex lbc_mutex = G_STATIC_REC_MUTEX_INIT;
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 
 static void
 lbc_lock(void)
 {
+#if GLIB_CHECK_VERSION(2, 32, 0)
     g_rec_mutex_lock(&lbc_mutex);
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+    g_static_rec_mutex_lock(&lbc_mutex);
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
     lbc_init(&lbc_conf, "config", ".gnome2");
     lbc_init(&lbc_conf_priv, "config-private", ".gnome2_private");
 }
@@ -160,7 +168,11 @@ lbc_lock(void)
 static void
 lbc_unlock(void)
 {
+#if GLIB_CHECK_VERSION(2, 32, 0)
     g_rec_mutex_unlock(&lbc_mutex);
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+    g_static_rec_mutex_unlock(&lbc_mutex);
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 }
 #else                           /* BALSA_USE_THREADS */
 static void
diff --git a/libbalsa/mime-stream-shared.c b/libbalsa/mime-stream-shared.c
index 6a278ec..f18564b 100644
--- a/libbalsa/mime-stream-shared.c
+++ b/libbalsa/mime-stream-shared.c
@@ -71,8 +71,13 @@ static GMimeStream *lbmss_stream_substream(GMimeStream * stream,
                                            gint64 start, gint64 end);
 
 static GMimeStreamFsClass *parent_class = NULL;
+#if GLIB_CHECK_VERSION(2, 32, 0)
 static GMutex lbmss_mutex;
 static GCond lbmss_cond;
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+static GMutex *lbmss_mutex;
+static GCond *lbmss_cond;
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 
 GType
 libbalsa_mime_stream_shared_get_type(void)
@@ -107,6 +112,10 @@ lbmss_stream_class_init(LibBalsaMimeStreamSharedClass * klass)
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
 
     parent_class = g_type_class_ref(GMIME_TYPE_STREAM_FS);
+#if !GLIB_CHECK_VERSION(2, 32, 0)
+    lbmss_mutex  = g_mutex_new();
+    lbmss_cond   = g_cond_new();
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 
     object_class->finalize  = lbmss_finalize;
 
@@ -280,12 +289,21 @@ libbalsa_mime_stream_shared_lock(GMimeStream * stream)
     lock = stream_shared->lock;
     thread_self = g_thread_self();
 
+#if GLIB_CHECK_VERSION(2, 32, 0)
     g_mutex_lock(&lbmss_mutex);
     while (lock->count > 0 && lock->thread != thread_self)
         g_cond_wait(&lbmss_cond, &lbmss_mutex);
     ++lock->count;
     lock->thread = thread_self;
     g_mutex_unlock(&lbmss_mutex);
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+    g_mutex_lock(lbmss_mutex);
+    while (lock->count > 0 && lock->thread != thread_self)
+        g_cond_wait(&lbmss_cond, lbmss_mutex);
+    ++lock->count;
+    lock->thread = thread_self;
+    g_mutex_unlock(lbmss_mutex);
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 }
 
 /**
@@ -312,10 +330,17 @@ libbalsa_mime_stream_shared_unlock(GMimeStream * stream)
     lock = stream_shared->lock;
     g_return_if_fail(lock->count > 0);
 
+#if GLIB_CHECK_VERSION(2, 32, 0)
     g_mutex_lock(&lbmss_mutex);
     if (--lock->count == 0)
         g_cond_signal(&lbmss_cond);
     g_mutex_unlock(&lbmss_mutex);
+#else                           /* GLIB_CHECK_VERSION(2, 32, 0) */
+    g_mutex_lock(lbmss_mutex);
+    if (--lock->count == 0)
+        g_cond_signal(lbmss_cond);
+    g_mutex_unlock(lbmss_mutex);
+#endif                          /* GLIB_CHECK_VERSION(2, 32, 0) */
 }
 
 #endif                          /* BALSA_USE_THREADS */



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