[grilo-plugins/0.2.x: 10/30] youtube: Fix non-thread-safe refcounting



commit 9d10b3e461796b8d87b4fc13432c4545ce66d188
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Aug 28 16:53:33 2015 +0200

    youtube: Fix non-thread-safe refcounting
    
    Which could certainly cause a few bugs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741634

 src/youtube/grl-youtube.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/src/youtube/grl-youtube.c b/src/youtube/grl-youtube.c
index 44548d2..246c8a3 100644
--- a/src/youtube/grl-youtube.c
+++ b/src/youtube/grl-youtube.c
@@ -143,7 +143,7 @@ typedef struct {
   CategoryInfo *category_info;
   guint emitted;
   guint matches;
-  guint ref_count;
+  gint ref_count;
 } OperationSpec;
 
 typedef struct {
@@ -458,7 +458,7 @@ operation_spec_new (void)
   GRL_DEBUG ("Allocating new spec");
 
   os =  g_slice_new0 (OperationSpec);
-  os->ref_count = 1;
+  g_atomic_int_set (&os->ref_count, 1);
 
   return os;
 }
@@ -466,8 +466,7 @@ operation_spec_new (void)
 static void
 operation_spec_unref (OperationSpec *os)
 {
-  os->ref_count--;
-  if (os->ref_count == 0) {
+  if (g_atomic_int_dec_and_test (&os->ref_count)) {
     g_clear_object (&os->cancellable);
     g_slice_free (OperationSpec, os);
     GRL_DEBUG ("freeing spec");
@@ -478,7 +477,7 @@ static void
 operation_spec_ref (OperationSpec *os)
 {
   GRL_DEBUG ("Reffing spec");
-  os->ref_count++;
+  g_atomic_int_inc (&os->ref_count);
 }
 
 static void


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