aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/test/helper/alloc_counter.h
blob: 7011b61b9d59dd6846bf0e6882b3ab789af85adb (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 <util/system/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");
    }
};