[evolution-data-server] CamelCert: Use atomic operations to track reference count.



commit 101e0d84bf0399e4f59fc8de47af5568e52c8997
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Sep 22 10:04:47 2013 -0400

    CamelCert: Use atomic operations to track reference count.

 camel/camel-certdb.c |   14 ++++----------
 camel/camel-certdb.h |    2 +-
 2 files changed, 5 insertions(+), 11 deletions(-)
---
diff --git a/camel/camel-certdb.c b/camel/camel-certdb.c
index f89fb69..9dd8d5d 100644
--- a/camel/camel-certdb.c
+++ b/camel/camel-certdb.c
@@ -645,10 +645,9 @@ camel_certdb_cert_ref (CamelCertDB *certdb,
 {
        g_return_if_fail (CAMEL_IS_CERTDB (certdb));
        g_return_if_fail (cert != NULL);
+       g_return_if_fail (cert->refcount > 0);
 
-       g_mutex_lock (&certdb->priv->ref_lock);
-       cert->refcount++;
-       g_mutex_unlock (&certdb->priv->ref_lock);
+       g_atomic_int_inc (&cert->refcount);
 }
 
 static void
@@ -671,23 +670,18 @@ camel_certdb_cert_unref (CamelCertDB *certdb,
 
        g_return_if_fail (CAMEL_IS_CERTDB (certdb));
        g_return_if_fail (cert != NULL);
+       g_return_if_fail (cert->refcount > 0);
 
        class = CAMEL_CERTDB_GET_CLASS (certdb);
        g_return_if_fail (class->cert_free != NULL);
 
-       g_mutex_lock (&certdb->priv->ref_lock);
-
-       if (cert->refcount <= 1) {
+       if (g_atomic_int_dec_and_test (&cert->refcount)) {
                class->cert_free (certdb, cert);
                if (certdb->cert_chunks)
                        camel_memchunk_free (certdb->cert_chunks, cert);
                else
                        g_free (cert);
-       } else {
-               cert->refcount--;
        }
-
-       g_mutex_unlock (&certdb->priv->ref_lock);
 }
 
 static gboolean
diff --git a/camel/camel-certdb.h b/camel/camel-certdb.h
index faf197f..64c563b 100644
--- a/camel/camel-certdb.h
+++ b/camel/camel-certdb.h
@@ -77,7 +77,7 @@ typedef enum {
 } CamelCertTrust;
 
 typedef struct {
-       guint32 refcount;
+       volatile gint refcount;
 
        gchar *issuer;
        gchar *subject;


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