aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory
diff options
context:
space:
mode:
authorsandello <sandello@yandex-team.ru>2022-02-10 16:49:52 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:52 +0300
commit0cdbcf332f1f329f0a3d6759462ad71e7867ac08 (patch)
tree6866207854e212f8179cb77bd1e2435e49743f66 /library/cpp/yt/memory
parent3f5911a056d3dbc4bfd724740244a3a9c11575ef (diff)
downloadydb-0cdbcf332f1f329f0a3d6759462ad71e7867ac08.tar.gz
Restoring authorship annotation for <sandello@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yt/memory')
-rw-r--r--library/cpp/yt/memory/blob.cpp2
-rw-r--r--library/cpp/yt/memory/intrusive_ptr.h166
-rw-r--r--library/cpp/yt/memory/leaky_singleton.h2
-rw-r--r--library/cpp/yt/memory/ref.cpp18
-rw-r--r--library/cpp/yt/memory/ref.h72
-rw-r--r--library/cpp/yt/memory/ref_counted.h4
6 files changed, 132 insertions, 132 deletions
diff --git a/library/cpp/yt/memory/blob.cpp b/library/cpp/yt/memory/blob.cpp
index 86000b033b..1a332a576f 100644
--- a/library/cpp/yt/memory/blob.cpp
+++ b/library/cpp/yt/memory/blob.cpp
@@ -161,7 +161,7 @@ void TBlob::Allocate(size_t newCapacity)
TRefCountedTrackerFacade::AllocateSpace(TagCookie_, newCapacity);
#endif
}
-
+
void TBlob::Reallocate(size_t newCapacity)
{
if (!Begin_) {
diff --git a/library/cpp/yt/memory/intrusive_ptr.h b/library/cpp/yt/memory/intrusive_ptr.h
index 3dead7db1d..71d1e7c90c 100644
--- a/library/cpp/yt/memory/intrusive_ptr.h
+++ b/library/cpp/yt/memory/intrusive_ptr.h
@@ -13,9 +13,9 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
template <class T>
-class TIntrusivePtr
-{
-public:
+class TIntrusivePtr
+{
+public:
typedef T TUnderlying;
constexpr TIntrusivePtr() noexcept
@@ -34,67 +34,67 @@ public:
*/
TIntrusivePtr(T* obj, bool addReference = true) noexcept
: T_(obj)
- {
+ {
if (T_ && addReference) {
Ref(T_);
}
}
- //! Copy constructor.
+ //! Copy constructor.
TIntrusivePtr(const TIntrusivePtr& other) noexcept
: T_(other.Get())
- {
+ {
if (T_) {
Ref(T_);
- }
- }
+ }
+ }
//! Copy constructor with an upcast.
template <class U, class = typename std::enable_if_t<std::is_convertible_v<U*, T*>>>
TIntrusivePtr(const TIntrusivePtr<U>& other) noexcept
- : T_(other.Get())
- {
+ : T_(other.Get())
+ {
static_assert(
std::is_base_of_v<TRefCountedBase, T>,
"Cast allowed only for types derived from TRefCountedBase");
if (T_) {
Ref(T_);
}
- }
+ }
- //! Move constructor.
+ //! Move constructor.
TIntrusivePtr(TIntrusivePtr&& other) noexcept
: T_(other.Get())
- {
+ {
other.T_ = nullptr;
- }
-
+ }
+
//! Move constructor with an upcast.
template <class U, class = typename std::enable_if_t<std::is_convertible_v<U*, T*>>>
TIntrusivePtr(TIntrusivePtr<U>&& other) noexcept
- : T_(other.Get())
- {
+ : T_(other.Get())
+ {
static_assert(
std::is_base_of_v<TRefCountedBase, T>,
"Cast allowed only for types derived from TRefCountedBase");
other.T_ = nullptr;
- }
-
- //! Destructor.
- ~TIntrusivePtr()
- {
+ }
+
+ //! Destructor.
+ ~TIntrusivePtr()
+ {
if (T_) {
Unref(T_);
}
- }
+ }
- //! Copy assignment operator.
+ //! Copy assignment operator.
TIntrusivePtr& operator=(const TIntrusivePtr& other) noexcept
- {
- TIntrusivePtr(other).Swap(*this);
- return *this;
- }
-
+ {
+ TIntrusivePtr(other).Swap(*this);
+ return *this;
+ }
+
//! Copy assignment operator with an upcast.
template <class U>
TIntrusivePtr& operator=(const TIntrusivePtr<U>& other) noexcept
@@ -109,13 +109,13 @@ public:
return *this;
}
- //! Move assignment operator.
+ //! Move assignment operator.
TIntrusivePtr& operator=(TIntrusivePtr&& other) noexcept
- {
+ {
TIntrusivePtr(std::move(other)).Swap(*this);
- return *this;
- }
-
+ return *this;
+ }
+
//! Move assignment operator with an upcast.
template <class U>
TIntrusivePtr& operator=(TIntrusivePtr<U>&& other) noexcept
@@ -132,22 +132,22 @@ public:
//! Drop the pointer.
void Reset() // noexcept
- {
- TIntrusivePtr().Swap(*this);
- }
-
+ {
+ TIntrusivePtr().Swap(*this);
+ }
+
//! Replace the pointer with a specified one.
void Reset(T* p) // noexcept
- {
- TIntrusivePtr(p).Swap(*this);
- }
-
+ {
+ TIntrusivePtr(p).Swap(*this);
+ }
+
//! Returns the pointer.
T* Get() const noexcept
{
- return T_;
- }
-
+ return T_;
+ }
+
//! Returns the pointer and releases the ownership.
T* Release() noexcept
{
@@ -157,17 +157,17 @@ public:
}
T& operator*() const noexcept
- {
+ {
YT_ASSERT(T_);
- return *T_;
- }
-
+ return *T_;
+ }
+
T* operator->() const noexcept
- {
+ {
YT_ASSERT(T_);
return T_;
- }
-
+ }
+
explicit operator bool() const noexcept
{
return T_ != nullptr;
@@ -176,12 +176,12 @@ public:
//! Swap the pointer with the other one.
void Swap(TIntrusivePtr& r) noexcept
{
- DoSwap(T_, r.T_);
- }
-
-private:
+ DoSwap(T_, r.T_);
+ }
+
+private:
template <class U>
- friend class TIntrusivePtr;
+ friend class TIntrusivePtr;
T* T_ = nullptr;
};
@@ -268,59 +268,59 @@ bool operator>(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<T>& rhs)
}
template <class T, class U>
-bool operator==(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs)
-{
+bool operator==(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs)
+{
static_assert(
std::is_convertible_v<U*, T*>,
"U* must be convertible to T*");
- return lhs.Get() == rhs.Get();
-}
-
+ return lhs.Get() == rhs.Get();
+}
+
template <class T, class U>
-bool operator!=(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs)
-{
+bool operator!=(const TIntrusivePtr<T>& lhs, const TIntrusivePtr<U>& rhs)
+{
static_assert(
std::is_convertible_v<U*, T*>,
"U* must be convertible to T*");
- return lhs.Get() != rhs.Get();
-}
-
+ return lhs.Get() != rhs.Get();
+}
+
template <class T, class U>
bool operator==(const TIntrusivePtr<T>& lhs, U* rhs)
-{
+{
static_assert(
std::is_convertible_v<U*, T*>,
"U* must be convertible to T*");
- return lhs.Get() == rhs;
-}
-
+ return lhs.Get() == rhs;
+}
+
template <class T, class U>
bool operator!=(const TIntrusivePtr<T>& lhs, U* rhs)
-{
+{
static_assert(
std::is_convertible_v<U*, T*>,
"U* must be convertible to T*");
- return lhs.Get() != rhs;
-}
-
+ return lhs.Get() != rhs;
+}
+
template <class T, class U>
bool operator==(T* lhs, const TIntrusivePtr<U>& rhs)
-{
+{
static_assert(
std::is_convertible_v<U*, T*>,
"U* must be convertible to T*");
- return lhs == rhs.Get();
-}
-
+ return lhs == rhs.Get();
+}
+
template <class T, class U>
bool operator!=(T* lhs, const TIntrusivePtr<U>& rhs)
-{
+{
static_assert(
std::is_convertible_v<U*, T*>,
"U* must be convertible to T*");
- return lhs != rhs.Get();
-}
-
+ return lhs != rhs.Get();
+}
+
template <class T>
bool operator==(std::nullptr_t, const TIntrusivePtr<T>& rhs)
{
diff --git a/library/cpp/yt/memory/leaky_singleton.h b/library/cpp/yt/memory/leaky_singleton.h
index 03b5e51d78..9ca0bb906d 100644
--- a/library/cpp/yt/memory/leaky_singleton.h
+++ b/library/cpp/yt/memory/leaky_singleton.h
@@ -22,7 +22,7 @@ private:
template <class T> \
friend class ::NYT::TLeakyStorage;
-template <class T>
+template <class T>
T* LeakySingleton();
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/memory/ref.cpp b/library/cpp/yt/memory/ref.cpp
index e8ff42e976..1ac4d4e99e 100644
--- a/library/cpp/yt/memory/ref.cpp
+++ b/library/cpp/yt/memory/ref.cpp
@@ -271,10 +271,10 @@ TSharedMutableRef TSharedMutableRef::MakeCopy(TRef ref, TRefCountedTypeCookie ta
TString ToString(TRef ref)
{
- return TString(ref.Begin(), ref.End());
+ return TString(ref.Begin(), ref.End());
}
-TString ToString(const TMutableRef& ref)
+TString ToString(const TMutableRef& ref)
{
return ToString(TRef(ref));
}
@@ -284,17 +284,17 @@ TString ToString(const TSharedRef& ref)
return ToString(TRef(ref));
}
-TString ToString(const TSharedMutableRef& ref)
+TString ToString(const TSharedMutableRef& ref)
{
return ToString(TRef(ref));
}
-size_t GetPageSize()
-{
- static const size_t PageSize = NSystemInfo::GetPageSize();
- return PageSize;
-}
-
+size_t GetPageSize()
+{
+ static const size_t PageSize = NSystemInfo::GetPageSize();
+ return PageSize;
+}
+
size_t RoundUpToPage(size_t bytes)
{
static const size_t PageSize = NSystemInfo::GetPageSize();
diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h
index 73d19d9013..0f27d24c77 100644
--- a/library/cpp/yt/memory/ref.h
+++ b/library/cpp/yt/memory/ref.h
@@ -1,29 +1,29 @@
-#pragma once
-
+#pragma once
+
#include "new.h"
#include "range.h"
#include "shared_range.h"
#include <type_traits>
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
// Forward declaration.
class TBlob;
//! A non-owning reference to a range of memory.
-class TRef
+class TRef
: public TRange<char>
-{
-public:
+{
+public:
//! Creates a null TRef.
TRef() = default;
-
+
//! Creates a TRef for a given block of memory.
TRef(const void* data, size_t size);
-
+
//! Creates a TRef for a given range of memory.
TRef(const void* begin, const void* end);
@@ -32,7 +32,7 @@ public:
//! Creates a non-owning TRef for a given blob.
static TRef FromBlob(const TBlob& blob);
-
+
//! Creates a non-owning TRef for a given string.
static TRef FromString(const TString& str);
@@ -45,11 +45,11 @@ public:
//! Creates a TRef for a part of existing range.
TRef Slice(size_t startOffset, size_t endOffset) const;
-
+
//! Compares the content for bitwise equality.
static bool AreBitwiseEqual(TRef lhs, TRef rhs);
};
-
+
////////////////////////////////////////////////////////////////////////////////
//! A non-owning reference to a mutable range of memory.
@@ -77,7 +77,7 @@ public:
//! Creates a non-owning TMutableRef for a given blob.
static TMutableRef FromBlob(TBlob& blob);
-
+
//! Creates a non-owning TMutableRef for a given pod structure.
template <class T>
static TMutableRef FromPod(T& data);
@@ -88,10 +88,10 @@ public:
//! Creates a TMutableRef for a part of existing range.
TMutableRef Slice(size_t startOffset, size_t endOffset) const;
-};
-
-////////////////////////////////////////////////////////////////////////////////
-
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
//! Default tag type for memory blocks allocated via TSharedRef.
/*!
* Each newly allocated TSharedRef blob is associated with a tag type
@@ -100,10 +100,10 @@ public:
struct TDefaultSharedBlobTag { };
//! A reference to a range of memory with shared ownership.
-class TSharedRef
+class TSharedRef
: public TSharedRange<char>
-{
-public:
+{
+public:
//! Creates a null TSharedRef.
TSharedRef() = default;
@@ -141,7 +141,7 @@ public:
//! Creates a TSharedRef for a given blob taking ownership of its content.
static TSharedRef FromBlob(TBlob&& blob);
-
+
//! Creates a copy of a given TRef.
//! The memory is marked with a given tag.
static TSharedRef MakeCopy(TRef ref, TRefCountedTypeCookie tagCookie);
@@ -150,13 +150,13 @@ public:
//! The memory is marked with a given tag.
template <class TTag>
static TSharedRef MakeCopy(TRef ref);
-
+
//! Creates a TSharedRef for a part of existing range.
TSharedRef Slice(size_t startOffset, size_t endOffset) const;
-
+
//! Creates a TSharedRef for a part of existing range.
TSharedRef Slice(const void* begin, const void* end) const;
-
+
//! Creates a vector of slices with specified size.
std::vector<TSharedRef> Split(size_t partSize) const;
@@ -189,13 +189,13 @@ public:
//! Converts a TSharedMutableRef to TMutableRef.
operator TMutableRef() const;
-
+
//! Converts a TSharedMutableRef to TSharedRef.
operator TSharedRef() const;
-
+
//! Converts a TSharedMutableRef to TRef.
operator TRef() const;
-
+
//! Allocates a new shared block of memory.
//! The memory is marked with a given tag.
@@ -301,8 +301,8 @@ private:
size_t poolCapacity,
TRefCountedTypeCookie cookie,
As&&... args);
-};
-
+};
+
// STL interop.
const TSharedRef* begin(const TSharedRefArray& array);
const TSharedRef* end(const TSharedRefArray& array);
@@ -361,11 +361,11 @@ private:
////////////////////////////////////////////////////////////////////////////////
TString ToString(TRef ref);
-TString ToString(const TMutableRef& ref);
-TString ToString(const TSharedRef& ref);
-TString ToString(const TSharedMutableRef& ref);
+TString ToString(const TMutableRef& ref);
+TString ToString(const TSharedRef& ref);
+TString ToString(const TSharedMutableRef& ref);
-size_t GetPageSize();
+size_t GetPageSize();
size_t RoundUpToPage(size_t bytes);
size_t GetByteSize(TRef ref);
@@ -377,7 +377,7 @@ size_t GetByteSize(const std::vector<T>& parts);
////////////////////////////////////////////////////////////////////////////////
-} // namespace NYT
+} // namespace NYT
#define REF_INL_H_
#include "ref-inl.h"
diff --git a/library/cpp/yt/memory/ref_counted.h b/library/cpp/yt/memory/ref_counted.h
index b683615b83..5b8b9faba7 100644
--- a/library/cpp/yt/memory/ref_counted.h
+++ b/library/cpp/yt/memory/ref_counted.h
@@ -6,8 +6,8 @@
#include <library/cpp/ytalloc/api/ytalloc.h>
-#include <atomic>
-
+#include <atomic>
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////