aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/test/helper/alloc_counter.h
blob: 93972b52dddebfd686dcc44e578b2d72ca1b68b0 (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_ABORT_UNLESS(AtomicDecrement(*CountPtr) >= 0, "released too many");
    }
};