Block cache WIP and other fixes

- Block cache is implemented only on Windows for now
- Tracking of background jobs
- More robust sidechain syncing
This commit is contained in:
SChernykh
2021-08-24 11:42:41 +02:00
parent 86b31ea821
commit aba3bc50b8
13 changed files with 461 additions and 57 deletions

View File

@@ -18,6 +18,9 @@
#include "common.h"
#include "util.h"
#include "uv_util.h"
#include <map>
#include <thread>
#include <chrono>
#ifndef _WIN32
#include <sched.h>
@@ -27,8 +30,6 @@ static constexpr char log_category_prefix[] = "Util ";
namespace p2pool {
std::atomic<int32_t> num_running_jobs{ 0 };
MinerCallbackHandler::~MinerCallbackHandler() {}
void panic()
@@ -131,4 +132,85 @@ void uv_rwlock_init_checked(uv_rwlock_t* lock)
}
}
struct BackgroundJobTracker::Impl
{
Impl() { uv_mutex_init_checked(&m_lock); }
~Impl() { uv_mutex_destroy(&m_lock); }
void start(const char* name)
{
MutexLock lock(m_lock);
auto it = m_jobs.insert({ name, 1 });
if (!it.second) {
++it.first->second;
}
}
void stop(const char* name)
{
MutexLock lock(m_lock);
auto it = m_jobs.find(name);
if (it == m_jobs.end()) {
LOGWARN(1, "background job " << name << " is not running, but stop() was called");
return;
}
--it->second;
if (it->second <= 0) {
m_jobs.erase(it);
}
}
void wait()
{
do {
bool is_empty = true;
{
MutexLock lock(m_lock);
is_empty = m_jobs.empty();
for (const auto& job : m_jobs) {
LOGINFO(1, "waiting for " << job.second << " \"" << job.first << "\" jobs to finish");
}
}
if (is_empty) {
return;
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
} while (1);
}
uv_mutex_t m_lock;
std::map<const char*, int32_t> m_jobs;
};
BackgroundJobTracker::BackgroundJobTracker() : m_impl(new Impl())
{
}
BackgroundJobTracker::~BackgroundJobTracker()
{
delete m_impl;
}
void BackgroundJobTracker::start(const char* name)
{
m_impl->start(name);
}
void BackgroundJobTracker::stop(const char* name)
{
m_impl->stop(name);
}
void BackgroundJobTracker::wait()
{
m_impl->wait();
}
BackgroundJobTracker bkg_jobs_tracker;
} // namespace p2pool