MCPcopy Create free account
hub / github.com/catboost/catboost / TLockFreeSequence

Class TLockFreeSequence

library/cpp/neh/http_common.h:90–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89 template <class T>
90 class TLockFreeSequence {
91 public:
92 inline TLockFreeSequence() {
93 memset((void*)T_, 0, sizeof(T_));
94 }
95
96 inline ~TLockFreeSequence() {
97 for (size_t i = 0; i < Y_ARRAY_SIZE(T_); ++i) {
98 delete[] T_[i];
99 }
100 }
101
102 inline T& Get(size_t n) {
103 const size_t i = GetValueBitCount(n + 1) - 1;
104
105 return GetList(i)[n + 1 - (((size_t)1) << i)];
106 }
107
108 private:
109 inline T* GetList(size_t n) {
110 T* volatile* t = T_ + n;
111
112 T* result;
113 while (!(result = AtomicGet(*t))) {
114 TArrayHolder<T> nt(new T[((size_t)1) << n]);
115
116 if (AtomicCas(t, nt.Get(), nullptr)) {
117 return nt.Release();
118 }
119 }
120
121 return result;
122 }
123
124 private:
125 T* volatile T_[sizeof(size_t) * 8];
126 };
127
128 class TRequestData: public TNonCopyable {
129 public:

Callers

nothing calls this directly

Calls 1

GetValueBitCountFunction · 0.85

Tested by

no test coverage detected