aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/util/queue_chunk.h
blob: 8a4e02d8cb485dd4e6cf7a7d5e23f3142c7ef7d0 (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
29
#pragma once

#include "defs.h"

template <typename T, ui32 TSize, typename TDerived>
struct TQueueChunkDerived {
    static const ui32 EntriesCount = (TSize - sizeof(TQueueChunkDerived*)) / sizeof(T);
    static_assert(EntriesCount > 0, "expect EntriesCount > 0");

    volatile T Entries[EntriesCount];
    TDerived* volatile Next;

    TQueueChunkDerived() {
        memset(this, 0, sizeof(TQueueChunkDerived));
    }
};

template <typename T, ui32 TSize>
struct TQueueChunk {
    static const ui32 EntriesCount = (TSize - sizeof(TQueueChunk*)) / sizeof(T);
    static_assert(EntriesCount > 0, "expect EntriesCount > 0");

    volatile T Entries[EntriesCount];
    TQueueChunk* volatile Next;

    TQueueChunk() {
        memset(this, 0, sizeof(TQueueChunk));
    }
};