use_count_checker.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "use_count_checker.h"
  2. #include <util/generic/utility.h>
  3. #include <util/system/yassert.h>
  4. TUseCountChecker::TUseCountChecker() {
  5. }
  6. TUseCountChecker::~TUseCountChecker() {
  7. auto count = Counter.Val();
  8. Y_ABORT_UNLESS(count == 0, "must not release when count is not zero: %ld", (long)count);
  9. }
  10. void TUseCountChecker::Inc() {
  11. Counter.Inc();
  12. }
  13. void TUseCountChecker::Dec() {
  14. Counter.Dec();
  15. }
  16. TUseCountHolder::TUseCountHolder()
  17. : CurrentChecker(nullptr)
  18. {
  19. }
  20. TUseCountHolder::TUseCountHolder(TUseCountChecker* currentChecker)
  21. : CurrentChecker(currentChecker)
  22. {
  23. if (!!CurrentChecker) {
  24. CurrentChecker->Inc();
  25. }
  26. }
  27. TUseCountHolder::~TUseCountHolder() {
  28. if (!!CurrentChecker) {
  29. CurrentChecker->Dec();
  30. }
  31. }
  32. TUseCountHolder& TUseCountHolder::operator=(TUseCountHolder that) {
  33. Swap(that);
  34. return *this;
  35. }
  36. void TUseCountHolder::Swap(TUseCountHolder& that) {
  37. DoSwap(CurrentChecker, that.CurrentChecker);
  38. }
  39. void TUseCountHolder::Reset() {
  40. TUseCountHolder tmp;
  41. Swap(tmp);
  42. }