Fix: headers: add missing end of `extern "C"` curly brackets (for C++)
[babeltrace.git] / include / babeltrace / object-internal.h
index b5a7a1f845f1efd54e911ad53cdc5ceb78c401c5..00f48ef675e6bdd3cb0b4ebca47ca85c6a1ddc95 100644 (file)
@@ -2,10 +2,9 @@
 #define BABELTRACE_OBJECT_INTERNAL_H
 
 /*
+ * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -325,4 +324,51 @@ void bt_object_put_no_null_check(const void *c_obj)
        }
 }
 
+static inline
+void bt_object_get_ref(const void *ptr)
+{
+       struct bt_object *obj = (void *) ptr;
+
+       if (unlikely(!obj)) {
+               return;
+       }
+
+#ifdef BT_ASSERT_PRE
+       BT_ASSERT_PRE(obj->is_shared, "Object is not shared: %!+O", obj);
+#endif
+
+       bt_object_get_no_null_check(obj);
+}
+
+static inline
+void bt_object_put_ref(const void *ptr)
+{
+       struct bt_object *obj = (void *) ptr;
+
+       if (unlikely(!obj)) {
+               return;
+       }
+
+#ifdef BT_ASSERT_PRE
+       BT_ASSERT_PRE(obj->is_shared, "Object is not shared: %!+O", obj);
+       BT_ASSERT_PRE(bt_object_get_ref_count(obj) > 0,
+               "Decrementing a reference count set to 0: %!+O", ptr);
+#endif
+
+       bt_object_put_no_null_check(obj);
+}
+
+#define BT_OBJECT_PUT_REF_AND_RESET(_var)      \
+       do {                                    \
+               bt_object_put_ref(_var);        \
+               (_var) = NULL;                  \
+       } while (0)
+
+#define BT_OBJECT_MOVE_REF(_var_dst, _var_src) \
+       do {                                    \
+               bt_object_put_ref(_var_dst);    \
+               (_var_dst) = (_var_src);        \
+               (_var_src) = NULL;              \
+       } while (0)
+
 #endif /* BABELTRACE_OBJECT_INTERNAL_H */
This page took 0.025036 seconds and 4 git commands to generate.