aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/tls_scratch-inl.h
blob: 32c26d67c086ae0c37fc639aa785395aa72abda5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef TLS_SCRATH_INL_H_
#error "Direct inclusion of this file is not allowed, include tls_scratch.h"
// For the sake of sane code completion.
#include "tls_scratch.h"
#endif

#include <library/cpp/yt/misc/tls.h>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

template <class T>
TMutableRange<T> GetTlsScratchBuffer(size_t size)
{
    // This is a workround for std::vector<bool>.
    using TBoxed = std::array<T, 1>;
    YT_THREAD_LOCAL(std::vector<TBoxed>) tlsVector;
    auto& vector = GetTlsRef(tlsVector);
    vector.reserve(size);
    auto range = TMutableRange(reinterpret_cast<T*>(vector.data()), size);
    std::fill(range.begin(), range.end(), T());
    return range;
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT