ir: add BT_CTF_MOVE()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 22 Jul 2015 21:05:36 +0000 (17:05 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 28 Jul 2015 18:00:26 +0000 (14:00 -0400)
Adds semantics to ownership transfers of CTF IR objects.

This is something that is done often enough to justify the
existence of this macro:

    struct bt_ctf_field_type *type;
    struct bt_ctf_field_type *ret_type;

    /* ... */

    /* move ownership */
    ret_type = type;
    type = NULL;

    /* ... */

    /* put both (safe since type was set to NULL) */
    bt_ctf_put(ret_type);
    bt_ctf_put(type);

With BT_CTF_MOVE():

    struct bt_ctf_field_type *type;
    struct bt_ctf_field_type *ret_type;

    /* ... */

    /* move ownership */
    BT_CTF_MOVE(ret_type, type);

    /* ... */

    /* put both (safe since ownership was moved) */
    bt_ctf_put(ret_type);
    bt_ctf_put(type);

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/ctf-ir/ref.h

index fa612ca0a9ed33174952dce36a2c5e0f36b12b76..acc89d175b6ddda805cb5f686cea04ff8cb6fe8c 100644 (file)
                (_obj) = NULL;          \
        } while (0)
 
+/*
+ * BT_CTF_MOVE: moves the ownership of a CTF object, setting the old
+ *     owner to NULL.
+ *
+ * This macro sets the variable _dst to the value of the variable _src,
+ * then sets _src to NULL, effectively moving the ownership of a CTF
+ * object from one variable to the other.
+ *
+ * @param obj CTF IR object.
+ */
+#define BT_CTF_MOVE(_dst, _src)                \
+       do {                            \
+               (_dst) = (_src);        \
+               (_src) = NULL;          \
+       } while (0)
+
 /*
  * bt_ctf_get: increments the reference count of a CTF IR object.
  *
This page took 0.033651 seconds and 4 git commands to generate.