aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/util/queue_oneone_inplace.h
diff options
context:
space:
mode:
authorddoarn <ddoarn@yandex-team.ru>2022-02-10 16:49:53 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:53 +0300
commit3bf10d3f40b502d181ef52f5c4602c98cb135360 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/actors/util/queue_oneone_inplace.h
parent0783fe3f48d91a3b741ce2ea32b11fbfc1637e7e (diff)
downloadydb-3bf10d3f40b502d181ef52f5c4602c98cb135360.tar.gz
Restoring authorship annotation for <ddoarn@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/actors/util/queue_oneone_inplace.h')
-rw-r--r--library/cpp/actors/util/queue_oneone_inplace.h218
1 files changed, 109 insertions, 109 deletions
diff --git a/library/cpp/actors/util/queue_oneone_inplace.h b/library/cpp/actors/util/queue_oneone_inplace.h
index 48507a5235..d7ec8bb21c 100644
--- a/library/cpp/actors/util/queue_oneone_inplace.h
+++ b/library/cpp/actors/util/queue_oneone_inplace.h
@@ -1,118 +1,118 @@
-#pragma once
-
-#include "defs.h"
-#include "queue_chunk.h"
-
-template <typename T, ui32 TSize, typename TChunk = TQueueChunk<T, TSize>>
-class TOneOneQueueInplace : TNonCopyable {
+#pragma once
+
+#include "defs.h"
+#include "queue_chunk.h"
+
+template <typename T, ui32 TSize, typename TChunk = TQueueChunk<T, TSize>>
+class TOneOneQueueInplace : TNonCopyable {
static_assert(std::is_integral<T>::value || std::is_pointer<T>::value, "expect std::is_integral<T>::value || std::is_pointer<T>::valuer");
-
- TChunk* ReadFrom;
- ui32 ReadPosition;
- ui32 WritePosition;
- TChunk* WriteTo;
-
- friend class TReadIterator;
-
-public:
- class TReadIterator {
- TChunk* ReadFrom;
- ui32 ReadPosition;
-
- public:
- TReadIterator(TChunk* readFrom, ui32 readPosition)
- : ReadFrom(readFrom)
- , ReadPosition(readPosition)
- {
- }
-
- inline T Next() {
- TChunk* head = ReadFrom;
- if (ReadPosition != TChunk::EntriesCount) {
- return AtomicLoad(&head->Entries[ReadPosition++]);
- } else if (TChunk* next = AtomicLoad(&head->Next)) {
- ReadFrom = next;
- ReadPosition = 0;
- return Next();
- }
+
+ TChunk* ReadFrom;
+ ui32 ReadPosition;
+ ui32 WritePosition;
+ TChunk* WriteTo;
+
+ friend class TReadIterator;
+
+public:
+ class TReadIterator {
+ TChunk* ReadFrom;
+ ui32 ReadPosition;
+
+ public:
+ TReadIterator(TChunk* readFrom, ui32 readPosition)
+ : ReadFrom(readFrom)
+ , ReadPosition(readPosition)
+ {
+ }
+
+ inline T Next() {
+ TChunk* head = ReadFrom;
+ if (ReadPosition != TChunk::EntriesCount) {
+ return AtomicLoad(&head->Entries[ReadPosition++]);
+ } else if (TChunk* next = AtomicLoad(&head->Next)) {
+ ReadFrom = next;
+ ReadPosition = 0;
+ return Next();
+ }
return T{};
- }
- };
-
- TOneOneQueueInplace()
- : ReadFrom(new TChunk())
- , ReadPosition(0)
- , WritePosition(0)
- , WriteTo(ReadFrom)
- {
- }
-
- ~TOneOneQueueInplace() {
+ }
+ };
+
+ TOneOneQueueInplace()
+ : ReadFrom(new TChunk())
+ , ReadPosition(0)
+ , WritePosition(0)
+ , WriteTo(ReadFrom)
+ {
+ }
+
+ ~TOneOneQueueInplace() {
Y_VERIFY_DEBUG(Head() == 0);
- delete ReadFrom;
- }
-
- struct TPtrCleanDestructor {
+ delete ReadFrom;
+ }
+
+ struct TPtrCleanDestructor {
static inline void Destroy(TOneOneQueueInplace<T, TSize>* x) noexcept {
- while (T head = x->Pop())
- delete head;
- delete x;
- }
- };
-
- struct TCleanDestructor {
+ while (T head = x->Pop())
+ delete head;
+ delete x;
+ }
+ };
+
+ struct TCleanDestructor {
static inline void Destroy(TOneOneQueueInplace<T, TSize>* x) noexcept {
while (x->Pop() != nullptr)
- continue;
- delete x;
- }
- };
-
- struct TPtrCleanInplaceMallocDestructor {
- template <typename TPtrVal>
+ continue;
+ delete x;
+ }
+ };
+
+ struct TPtrCleanInplaceMallocDestructor {
+ template <typename TPtrVal>
static inline void Destroy(TOneOneQueueInplace<TPtrVal*, TSize>* x) noexcept {
- while (TPtrVal* head = x->Pop()) {
- head->~TPtrVal();
- free(head);
- }
- delete x;
- }
- };
-
+ while (TPtrVal* head = x->Pop()) {
+ head->~TPtrVal();
+ free(head);
+ }
+ delete x;
+ }
+ };
+
void Push(T x) noexcept {
- if (WritePosition != TChunk::EntriesCount) {
- AtomicStore(&WriteTo->Entries[WritePosition], x);
- ++WritePosition;
- } else {
- TChunk* next = new TChunk();
- next->Entries[0] = x;
- AtomicStore(&WriteTo->Next, next);
- WriteTo = next;
- WritePosition = 1;
- }
- }
-
- T Head() {
- TChunk* head = ReadFrom;
- if (ReadPosition != TChunk::EntriesCount) {
- return AtomicLoad(&head->Entries[ReadPosition]);
- } else if (TChunk* next = AtomicLoad(&head->Next)) {
- ReadFrom = next;
- delete head;
- ReadPosition = 0;
- return Head();
- }
+ if (WritePosition != TChunk::EntriesCount) {
+ AtomicStore(&WriteTo->Entries[WritePosition], x);
+ ++WritePosition;
+ } else {
+ TChunk* next = new TChunk();
+ next->Entries[0] = x;
+ AtomicStore(&WriteTo->Next, next);
+ WriteTo = next;
+ WritePosition = 1;
+ }
+ }
+
+ T Head() {
+ TChunk* head = ReadFrom;
+ if (ReadPosition != TChunk::EntriesCount) {
+ return AtomicLoad(&head->Entries[ReadPosition]);
+ } else if (TChunk* next = AtomicLoad(&head->Next)) {
+ ReadFrom = next;
+ delete head;
+ ReadPosition = 0;
+ return Head();
+ }
return T{};
- }
-
- T Pop() {
- T ret = Head();
- if (ret)
- ++ReadPosition;
- return ret;
- }
-
- TReadIterator Iterator() {
- return TReadIterator(ReadFrom, ReadPosition);
- }
-};
+ }
+
+ T Pop() {
+ T ret = Head();
+ if (ret)
+ ++ReadPosition;
+ return ret;
+ }
+
+ TReadIterator Iterator() {
+ return TReadIterator(ReadFrom, ReadPosition);
+ }
+};