Object: Acquire reference to parent on first acquired reference
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 19 Jan 2016 18:22:59 +0000 (13:22 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 19 Jan 2016 18:29:49 +0000 (13:29 -0500)
See doc/ref-counting.md

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/ref.c

index e642e266de87543c24f9f3819e6c8b7a577c1b46..97460e93522a84505637d3ba80d69fb85c416405 100644 (file)
--- a/lib/ref.c
+++ b/lib/ref.c
 #include <babeltrace/ref-internal.h>
 #include <babeltrace/object-internal.h>
 
-void *bt_get(void *obj)
+void *bt_get(void *ptr)
 {
-       if (obj) {
-               struct bt_object *base = obj;
+       struct bt_object *obj = ptr;
+
+       if (!obj) {
+               goto end;
+       }
 
-               bt_ref_get(&base->ref_count);
+       if (obj->parent && bt_object_get_ref_count(obj) == 0) {
+               bt_get(obj->parent);
        }
+       bt_ref_get(&obj->ref_count);
+end:
        return obj;
 }
 
This page took 0.026231 seconds and 4 git commands to generate.