Skip to content

Commit

Permalink
Add nostd::unique_ptr APIs for CircularBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Oct 14, 2024
1 parent fa463ee commit 671e5cf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions sdk/include/opentelemetry/sdk/common/circular_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <memory>

#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/sdk/common/atomic_unique_ptr.h"
#include "opentelemetry/sdk/common/circular_buffer_range.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -83,7 +84,7 @@ class CircularBuffer
* @param ptr a pointer to the element to add
* @return true if the element was successfully added; false, otherwise.
*/
bool Add(std::unique_ptr<T> &ptr) noexcept
bool Add(nostd::unique_ptr<T> &ptr) noexcept
{
while (true)
{
Expand Down Expand Up @@ -118,14 +119,27 @@ class CircularBuffer
}
}

bool Add(std::unique_ptr<T> &&ptr) noexcept
bool Add(nostd::unique_ptr<T> &&ptr) noexcept
{
// rvalue to lvalue reference
bool result = Add(std::ref(ptr));
ptr.reset();
return result;
}

#if !defined(OPENTELEMETRY_HAVE_STD_UNIQUE_PTR)
bool Add(std::unique_ptr<T> &ptr) noexcept
{
nostd::unique_ptr<T> convert_ptr{std::move(ptr)};

bool result = Add(convert_ptr);
ptr.reset(convert_ptr.release());
return result;
}

bool Add(std::unique_ptr<T> &&ptr) noexcept { return Add(nostd::unique_ptr<T>{std::move(ptr)}); }
#endif

/**
* Clear the circular buffer.
*
Expand Down

0 comments on commit 671e5cf

Please sign in to comment.