lib: assign a unique ID to each pre/postcond. and report it on failure
[babeltrace.git] / src / lib / trace-ir / clock-snapshot.c
index 53f6be654478454fb051468c4e5cbfd75b33278d..55e3777b2f098ae123eaedf069959820fca14994 100644 (file)
@@ -1,33 +1,17 @@
 /*
- * Copyright 2017-2018 Philippe Proulx <pproulx@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
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * SPDX-License-Identifier: MIT
  *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  */
 
 #define BT_LOG_TAG "LIB/CLOCK-SNAPSHOT"
 #include "lib/logging.h"
 
-#include "lib/assert-pre.h"
-#include "compat/uuid.h"
+#include "lib/assert-cond.h"
+#include "common/uuid.h"
 #include "clock-class.h"
 #include "clock-snapshot.h"
-#include <babeltrace2/trace-ir/clock-snapshot-const.h>
+#include <babeltrace2/trace-ir/clock-snapshot.h>
 #include "compat/compiler.h"
 #include <babeltrace2/types.h>
 #include "compat/string.h"
@@ -39,6 +23,7 @@
 BT_HIDDEN
 void bt_clock_snapshot_destroy(struct bt_clock_snapshot *clock_snapshot)
 {
+       BT_ASSERT(clock_snapshot);
        BT_LIB_LOGD("Destroying clock snapshot: %!+k", clock_snapshot);
        BT_OBJECT_PUT_REF_AND_RESET(clock_snapshot->clock_class);
        g_free(clock_snapshot);
@@ -62,7 +47,7 @@ struct bt_clock_snapshot *bt_clock_snapshot_new(
 
        bt_object_init_unique(&ret->base);
        ret->clock_class = clock_class;
-       bt_object_get_no_null_check(clock_class);
+       bt_object_get_ref_no_null_check(clock_class);
        bt_clock_class_freeze(clock_class);
        BT_LIB_LOGD("Created clock snapshot object: %!+k", ret);
 
@@ -76,26 +61,18 @@ struct bt_clock_snapshot *bt_clock_snapshot_create(
 {
        struct bt_clock_snapshot *clock_snapshot = NULL;
 
-       BT_ASSERT(clock_class);
+       BT_ASSERT_DBG(clock_class);
        clock_snapshot = bt_object_pool_create_object(&clock_class->cs_pool);
        if (!clock_snapshot) {
                BT_LIB_LOGE_APPEND_CAUSE(
                        "Cannot allocate one clock snapshot from clock class's clock snapshot pool: "
                        "%![cc-]+K", clock_class);
-               goto error;
+               goto end;
        }
 
        if (G_LIKELY(!clock_snapshot->clock_class)) {
                clock_snapshot->clock_class = clock_class;
-               bt_object_get_no_null_check(clock_class);
-       }
-
-       goto end;
-
-error:
-       if (clock_snapshot) {
-               bt_clock_snapshot_recycle(clock_snapshot);
-               clock_snapshot = NULL;
+               bt_object_get_ref_no_null_check(clock_class);
        }
 
 end:
@@ -107,7 +84,7 @@ void bt_clock_snapshot_recycle(struct bt_clock_snapshot *clock_snapshot)
 {
        struct bt_clock_class *clock_class;
 
-       BT_ASSERT(clock_snapshot);
+       BT_ASSERT_DBG(clock_snapshot);
        BT_LIB_LOGD("Recycling clock snapshot: %!+k", clock_snapshot);
 
        /*
@@ -134,7 +111,7 @@ void bt_clock_snapshot_recycle(struct bt_clock_snapshot *clock_snapshot)
         */
        bt_clock_snapshot_reset(clock_snapshot);
        clock_class = clock_snapshot->clock_class;
-       BT_ASSERT(clock_class);
+       BT_ASSERT_DBG(clock_class);
        clock_snapshot->clock_class = NULL;
        bt_object_pool_recycle_object(&clock_class->cs_pool, clock_snapshot);
        bt_object_put_ref(clock_class);
@@ -143,9 +120,8 @@ void bt_clock_snapshot_recycle(struct bt_clock_snapshot *clock_snapshot)
 uint64_t bt_clock_snapshot_get_value(
                const struct bt_clock_snapshot *clock_snapshot)
 {
-       BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot");
-       BT_ASSERT_PRE(clock_snapshot->is_set,
-               "Clock snapshot is not set: %!+k", clock_snapshot);
+       BT_ASSERT_PRE_DEV_CS_NON_NULL(clock_snapshot);
+       BT_ASSERT_DBG(clock_snapshot->is_set);
        return clock_snapshot->value_cycles;
 }
 
@@ -156,16 +132,18 @@ bt_clock_snapshot_get_ns_from_origin(
 {
        int ret = BT_FUNC_STATUS_OK;
 
-       BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot");
-       BT_ASSERT_PRE_NON_NULL(ret_value_ns, "Value (ns) (output)");
-       BT_ASSERT_PRE(clock_snapshot->is_set,
-               "Clock snapshot is not set: %!+k", clock_snapshot);
+       BT_ASSERT_PRE_DEV_NO_ERROR();
+       BT_ASSERT_PRE_DEV_CS_NON_NULL(clock_snapshot);
+       BT_ASSERT_PRE_DEV_NON_NULL("value-ns-output", ret_value_ns,
+               "Value (ns) (output)");
+       BT_ASSERT_DBG(clock_snapshot->is_set);
 
        if (clock_snapshot->ns_from_origin_overflows) {
-               BT_LIB_LOGD("Clock snapshot, once converted to nanoseconds from origin, "
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Clock snapshot, once converted to nanoseconds from origin, "
                        "overflows the signed 64-bit integer range: "
                        "%![cs-]+k", clock_snapshot);
-               ret = BT_FUNC_STATUS_OVERFLOW;
+               ret = BT_FUNC_STATUS_OVERFLOW_ERROR;
                goto end;
        }
 
@@ -178,6 +156,6 @@ end:
 const struct bt_clock_class *bt_clock_snapshot_borrow_clock_class_const(
                const struct bt_clock_snapshot *clock_snapshot)
 {
-       BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot");
+       BT_ASSERT_PRE_DEV_CS_NON_NULL(clock_snapshot);
        return clock_snapshot->clock_class;
 }
This page took 0.025555 seconds and 4 git commands to generate.