mactype/hookCounter.h
2023-08-22 17:48:13 +08:00

25 lines
389 B
C++

#pragma once
#include <atomic>
#include <thread>
#include <chrono>
class HCounter {
static std::atomic<int> ref;
public:
HCounter() {
++this->ref;
}
~HCounter() {
--this->ref;
}
static bool wait(int nCount) {
while (--nCount && HCounter::ref.load()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return !HCounter::ref;
}
};