newtx/scanner/res_mgr.h

36 lines
737 B
C
Raw Normal View History

2024-02-25 05:51:52 +00:00
// resource manager
//
// Date: 2024-02-25
//
// Resources in monitoring: memory
#pragma once
#include <base/utils.h>
#include <base/packet.h>
// #define USE_MONITOR_THREAD
2024-02-25 05:51:52 +00:00
class resource_mgr
{
volatile bool run_ = true;
volatile bool monitor_ = false;
uint64_t mem_limit_ = SIZE_MB(2500);
volatile uint64_t mem_now_ = 0;
2024-02-25 05:51:52 +00:00
std::unique_ptr<std::thread> thread_;
void thread_monitor(void);
public:
resource_mgr();
~resource_mgr();
static std::string task_type(_task task);
public:
void start(void);
void stop(void);
void set_memory_limit(uint64_t max_size = SIZE_GB(2));
bool is_resource_enable(_task task, bool wait = false, int to_ms = 0);
};