aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/test/helper/alloc_counter.h
blob: 7c4010714f5c475fe40e80592e65eae30e5c7cc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#pragma once

#include <util/generic/noncopyable.h>
#include <library/cpp/deprecated/atomic/atomic.h>
#include <util/system/yassert.h>

class TAllocCounter : TNonCopyable {
private:
    TAtomic* CountPtr;

public:
    TAllocCounter(TAtomic* countPtr)
        : CountPtr(countPtr)
    {
        AtomicIncrement(*CountPtr);
    }

    ~TAllocCounter() {
        Y_VERIFY(AtomicDecrement(*CountPtr) >= 0, "released too many");
    }
};