Move to WeakRef to avoid data races
authorMaciej Piechotka <uzytkownik2@gmail.com>
Sat, 25 Jan 2014 20:16:40 +0000 (21:16 +0100)
committerMaciej Piechotka <uzytkownik2@gmail.com>
Sat, 25 Jan 2014 20:16:40 +0000 (21:16 +0100)
gee/abstractbidirlist.vala
gee/abstractbidirsortedmap.vala
gee/abstractbidirsortedset.vala
gee/abstractcollection.vala
gee/abstractlist.vala
gee/abstractmap.vala
gee/abstractmultimap.vala
gee/abstractmultiset.vala
gee/abstractset.vala
gee/abstractsortedmap.vala
gee/abstractsortedset.vala

index 1f50a0f..4787d0a 100644 (file)
@@ -26,18 +26,20 @@ public abstract class Gee.AbstractBidirList<G> : AbstractList<G>, BidirList<G> {
         */
        public abstract BidirListIterator<G> bidir_list_iterator ();
 
-       private weak BidirList<G> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual new BidirList<G> read_only_view {
                owned get {
-                       BidirList<G> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       BidirList<G>? instance = (BidirList<G>?)_read_only_view.get();
+                       if (instance == null) {
                                instance = new ReadOnlyBidirList<G> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index bab090a..c3f5a70 100644 (file)
@@ -33,18 +33,20 @@ public abstract class Gee.AbstractBidirSortedMap<K,V> : Gee.AbstractSortedMap<K,
         */
        public abstract BidirMapIterator<K,V> bidir_map_iterator ();
 
-       private weak BidirSortedMap<K,V> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual new BidirSortedMap<K,V> read_only_view {
                owned get {
-                       BidirSortedMap<K,V> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       BidirSortedMap<K,V>? instance = (BidirSortedMap<K,V>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlyBidirSortedMap<K,V> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index 92ca920..4702c6b 100644 (file)
@@ -33,18 +33,20 @@ public abstract class Gee.AbstractBidirSortedSet<G> : Gee.AbstractSortedSet<G>,
         */
        public abstract BidirIterator<G> bidir_iterator ();
 
-       private weak BidirSortedSet<G> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual new BidirSortedSet<G> read_only_view {
                owned get {
-                       BidirSortedSet<G> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       BidirSortedSet<G>? instance = (BidirSortedSet<G>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlyBidirSortedSet<G> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index f7aa9b2..85e24f5 100644 (file)
@@ -70,18 +70,20 @@ public abstract class Gee.AbstractCollection<G> : Object, Traversable<G>, Iterab
                return iterator ().foreach (f);
        }
 
-       private weak Collection<G> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual Collection<G> read_only_view {
                owned get {
-                       Collection<G> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       Collection<G>? instance = (Collection<G>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlyCollection<G> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index 03650f6..eeff984 100644 (file)
@@ -66,18 +66,20 @@ public abstract class Gee.AbstractList<G> : Gee.AbstractCollection<G>, List<G> {
         */
        public abstract List<G>? slice (int start, int stop);
 
-       private weak List<G> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual new List<G> read_only_view {
                owned get {
-                       List<G> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       List<G>? instance = (List<G>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlyList<G> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index cd761b8..37abfe3 100644 (file)
@@ -91,18 +91,20 @@ public abstract class Gee.AbstractMap<K,V> : Object, Traversable<Map.Entry<K,V>>
         */
        public abstract void clear ();
 
-       private weak Map<K,V> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual Map<K,V> read_only_view {
                owned get {
-                       Map<K,V> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       Map<K,V>? instance = (Map<K,V>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlyMap<K,V> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index 12e84dd..0f17077 100644 (file)
@@ -309,14 +309,17 @@ public abstract class Gee.AbstractMultiMap<K,V> : Object, MultiMap<K,V> {
                public bool mutable { get { return false; } }
        }
 
-       private weak MultiMap<K, V> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
+
        public virtual new MultiMap<K, V> read_only_view {
                owned get {
-                       MultiMap<K, V> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       MultiMap<K, V>? instance = (MultiMap<K, V>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlyMultiMap<K, V> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index 3104c55..b237814 100644 (file)
@@ -92,14 +92,17 @@ public abstract class Gee.AbstractMultiSet<G> : AbstractCollection<G>, MultiSet<
                _nitems = 0;
        }
 
-       private weak MultiSet<G> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
+
        public virtual new MultiSet<G> read_only_view {
                owned get {
-                       MultiSet<G> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       MultiSet<G>? instance = (MultiSet<G>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlyMultiSet<G> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index 972b4d1..1d411c7 100644 (file)
  */
 public abstract class Gee.AbstractSet<G> : Gee.AbstractCollection<G>, Set<G> {
 
-       private weak Set<G> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual new Set<G> read_only_view {
                owned get {
-                       Set<G> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       Set<G>? instance = (Set<G>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlySet<G> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index 90ec215..fafe75d 100644 (file)
@@ -46,17 +46,20 @@ public abstract class Gee.AbstractSortedMap<K, V> : AbstractMap<K,V>, SortedMap<
         */
        public abstract SortedSet<Map.Entry<K,V>> ascending_entries { owned get; }
 
-       private weak SortedMap<K,V> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
+
        /**
         * The read-only view this map.
         */
        public new SortedMap<K,V> read_only_view {
                owned get {
-                       SortedMap<K,V> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       SortedMap<K,V>? instance = (SortedMap<K,V>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlySortedMap<K,V> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }
index 50daca2..eb83d3d 100644 (file)
@@ -78,18 +78,20 @@ public abstract class Gee.AbstractSortedSet<G> : Gee.AbstractSet<G>, SortedSet<G
         */
        public abstract SortedSet<G> sub_set (G from, G to);
 
-       private weak SortedSet<G> _read_only_view;
+       private WeakRef _read_only_view;
+       construct {
+               _read_only_view = WeakRef(null);
+       }
 
        /**
         * {@inheritDoc}
         */
        public virtual new SortedSet<G> read_only_view {
                owned get {
-                       SortedSet<G> instance = _read_only_view;
-                       if (_read_only_view == null) {
+                       SortedSet<G>? instance = (SortedSet<G>?)_read_only_view.get ();
+                       if (instance == null) {
                                instance = new ReadOnlySortedSet<G> (this);
-                               _read_only_view = instance;
-                               instance.add_weak_pointer ((void**) (&_read_only_view));
+                               _read_only_view.set (instance);
                        }
                        return instance;
                }