[libgee] Fix HazardPointer implementation



commit 00919a213195a661828b4d6dc68d4b26e8e105aa
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sat Mar 1 20:48:05 2014 +0100

    Fix HazardPointer implementation

 gee/hazardpointer.vala |   11 +++++++----
 utils/geeutils.vapi    |    2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gee/hazardpointer.vala b/gee/hazardpointer.vala
index 81a9306..7513751 100644
--- a/gee/hazardpointer.vala
+++ b/gee/hazardpointer.vala
@@ -165,8 +165,10 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
        public static void set_pointer<G> (G **aptr, owned G? new_ptr, size_t mask = 0, size_t new_mask = 0) {
                HazardPointer<G>? ptr = exchange_hazard_pointer<G> (aptr, new_ptr, mask, new_mask, null);
                if (ptr != null) {
-                       DestroyNotify notify = Utils.Free.get_destroy_notify<G> ();
-                       ptr.release ((owned)notify);
+                       DestroyNotify? notify = Utils.Free.get_destroy_notify<G> ();
+                       if (notify != null) {
+                               ptr.release ((owned)notify);
+                       }
                }
        }
 
@@ -202,8 +204,8 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
                void *old_rptr = (void *)((size_t)(old_ptr) | (mask & old_mask));
                bool success = AtomicPointer.compare_and_exchange((void **)aptr, old_rptr, new_rptr);
                if (success) {
-                       DestroyNotify notify = Utils.Free.get_destroy_notify<G> ();
-                       if (old_ptr != null) {
+                       DestroyNotify? notify = Utils.Free.get_destroy_notify<G> ();
+                       if (old_ptr != null && notify != null) {
                                Context.get_current_context ()->release_ptr (old_ptr, (owned)notify);
                        }
                } else if (new_ptr != null) {
@@ -480,6 +482,7 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
                                        _queue = new LinkedList<ArrayList<FreeNode *>> ();
                                        // Hack to not lie about successfull setting policy
                                        policy = AtomicInt.add (ref release_policy, (int)(1 << (sizeof(int) * 
8 - 1)));
+                                       _global_to_free = new ArrayList<FreeNode *> ();
                                        start ((ReleasePolicy) policy);
                                }
                                _queue_mutex.unlock ();
diff --git a/utils/geeutils.vapi b/utils/geeutils.vapi
index 988a337..b25a79e 100644
--- a/utils/geeutils.vapi
+++ b/utils/geeutils.vapi
@@ -6,7 +6,7 @@ namespace Gee {
                }
                namespace Free {
                        [CCode (cheader_filename = "free.h")]
-                       public GLib.DestroyNotify get_destroy_notify<G> ();
+                       public GLib.DestroyNotify? get_destroy_notify<G> ();
                }
                namespace Misc {
                        [CCode (cheader_filename = "misc.h", simple_generics = true)]


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