Add bt2::internal::SharedObj::create{With,Without}Ref() methods
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 13 May 2022 17:29:36 +0000 (13:29 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 11 Sep 2023 15:24:02 +0000 (11:24 -0400)
commitc9c0b6e232066c94b2f4637cf913762e8e71e13a
tree57c690cce8f382df550c61adc2ff6ad99b992120
parent9ce695a6f595a5a79957403d6c0dae36dd64bebe
Add bt2::internal::SharedObj::create{With,Without}Ref() methods

It seems like there were some confusion regarding the reference
acquisition of the `bt2::internal::SharedObj` constructor vs. its
createWithInitialRef() static method.

Make it clear with a private constructor and two public static methods:

* createWithoutRef() creates a shared object without getting a
  reference.

* createWithRef() creates a shared object, immediately getting a new
  reference.

Both methods have two versions: one which accepts a wrapper and one
which accepts a raw libbabeltrace2 pointer.

Update all the `src/cpp-common/bt2` code to use those methods.

The pattern for a non-static shared() method is:

    Shared shared() const noexcept
    {
        return Shared::createWithRef(*this);
    }

This means if you have a borrowed wrapper `obj`, then `obj.shared()`
returns a shared object, incrementing the reference count.

The pattern for a creation method is:

    return Shared::createWithoutRef(libObjPtr);

where `libObjPtr` is a raw libbabeltrace2 pointer to an object of which
the reference count is one.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ifeef4af74a0078c1b7e9e5dfec8ebd5be381da8f
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8039
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10797
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/clock-class.hpp
src/cpp-common/bt2/field-class.hpp
src/cpp-common/bt2/field-path.hpp
src/cpp-common/bt2/integer-range-set.hpp
src/cpp-common/bt2/internal/shared-obj.hpp
src/cpp-common/bt2/message.hpp
src/cpp-common/bt2/trace-ir.hpp
src/cpp-common/bt2/value.hpp
This page took 0.025016 seconds and 4 git commands to generate.