blob: 387688af39643b3dcf4dd81c33e7197f28ea6282 (
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "use_count_checker.h"
#include <util/generic/utility.h>
#include <util/system/yassert.h>
TUseCountChecker::TUseCountChecker() {
}
TUseCountChecker::~TUseCountChecker() {
TAtomicBase count = Counter.Val();
Y_VERIFY(count == 0, "must not release when count is not zero: %ld", (long)count);
}
void TUseCountChecker::Inc() {
Counter.Inc();
}
void TUseCountChecker::Dec() {
Counter.Dec();
}
TUseCountHolder::TUseCountHolder()
: CurrentChecker(nullptr)
{
}
TUseCountHolder::TUseCountHolder(TUseCountChecker* currentChecker)
: CurrentChecker(currentChecker)
{
if (!!CurrentChecker) {
CurrentChecker->Inc();
}
}
TUseCountHolder::~TUseCountHolder() {
if (!!CurrentChecker) {
CurrentChecker->Dec();
}
}
TUseCountHolder& TUseCountHolder::operator=(TUseCountHolder that) {
Swap(that);
return *this;
}
void TUseCountHolder::Swap(TUseCountHolder& that) {
DoSwap(CurrentChecker, that.CurrentChecker);
}
void TUseCountHolder::Reset() {
TUseCountHolder tmp;
Swap(tmp);
}
|