Code

utils llist: Let llist_get() increment the reference count.
[sysdb.git] / src / utils / llist.c
index c56cdbda098b581c9d957aeebb7db9c1725ffdf0..f009bcdac43cd30b3ccd51c0d79f953018f16e04 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include "utils/llist.h"
 
 #include <assert.h>
@@ -317,6 +321,7 @@ sdb_llist_get(sdb_llist_t *list, size_t i)
                /* iterate */;
 
        assert(elem);
+       sdb_object_ref(elem->obj);
        return elem->obj;
 } /* sdb_llist_get */
 
@@ -443,6 +448,11 @@ sdb_llist_iter_get_next(sdb_llist_iter_t *iter)
 
        pthread_rwlock_rdlock(&iter->list->lock);
 
+       /* XXX: increment ref-cnt for this object?
+        *      also: when letting an element take ownership of next and prev
+        *      elements, this might be a fairly cheap way to implement a weak
+        *      type of snapshotting */
+
        obj = iter->elem->obj;
        iter->elem = iter->elem->next;