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