mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-30 00:50:48 +08:00
31 lines
568 B
C++
31 lines
568 B
C++
#pragma once
|
|
#include <atomic>
|
|
#include <thread>
|
|
#include <chrono>
|
|
|
|
class qps {
|
|
public:
|
|
void increase() {
|
|
counter_.fetch_add(1, std::memory_order_release);
|
|
}
|
|
|
|
qps() : counter_(0) {
|
|
thd_ = std::thread([this] {
|
|
while (!stop_) {
|
|
std::cout << "qps: " << counter_.load(std::memory_order_acquire) << '\n';
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
//counter_.store(0, std::memory_order_release);
|
|
}
|
|
});
|
|
}
|
|
|
|
~qps() {
|
|
stop_ = true;
|
|
thd_.join();
|
|
}
|
|
|
|
private:
|
|
bool stop_ = false;
|
|
std::thread thd_;
|
|
std::atomic<uint32_t> counter_;
|
|
}; |