2ba0ecf428
Migration from boost to std-library equivalents and removal of unreachable code paths. Touches infrastructure only — no consensus rule or wallet serialization changes. Dead code removed: - IRC bootstrap (irc.cpp/h, 417 lines): orphan from pre-Tor era, no callers. - Alert system (alert.cpp/h + sendalert RPC + Qt UI signal, ~500 lines): retired post-V5 fork; old peers' alert messages now hit the unknown-cmd default branch, logged + ignored. - Legacy P2P handlers in main.cpp: "checkpoint" (already a no-op stub since V5 fork master-key removal), "checkorder"/"reply" (2010-era Receive-by-IP feature), plus their unused supporting structures (CRequestTracker, PushRequest overloads, mapRequests/cs_mapRequests, mapReuseKey). - Unreachable RPCs clearwallettransactions and scanforalltxns (~175 lines): defined in rpcwallet.cpp but never registered in the dispatch table. - Stale -alertnotify CLI help text (option was advertised but never wired). boost::filesystem -> std::filesystem (C++17): - 30 source files, 5 headers. namespace fs = boost::filesystem swapped to namespace fs = std::filesystem; boost::filesystem::ifstream/ofstream replaced with std::ifstream/ofstream (path-aware in C++17); fs::system_complete -> fs::absolute; boost::filesystem::filesystem_error -> std::filesystem::filesystem_error. - Build system: dropped Boost::filesystem from link libs and Boost components; PCH includes updated. - Added explicit <filesystem> includes where types were previously available only transitively (db.h, rpcblockchain.cpp). boost::thread -> std::thread (12 files): - sync.h CCriticalSection/CWaitableCriticalSection now alias std::recursive_mutex/std::mutex. boost::unique_lock and boost::condition_variable / boost::mutex::scoped_lock swapped to std equivalents; sync.cpp boost::thread_specific_ptr -> thread_local std::unique_ptr. - init.cpp boost::thread_group rewritten as std::vector<std::thread> with manual join loop. boost::thread::hardware_concurrency -> std::thread::hardware_concurrency. - main.cpp/wallet.cpp -blocknotify/-walletnotify shell-out threads now use std::thread(...).detach() — fixes a latent bug where modern boost::thread destructor would call std::terminate on the joinable thread. - util.cpp NewThread now catches std::system_error. - No interruption_point/interrupt usage anywhere — pure mechanical swap. boost::chrono / boost::posix_time -> std::chrono (3 of 5 files): - util.h: MilliSleep, GetTimeMillis, GetTimeMicros rewritten on std::chrono (system_clock for epoch math, sleep_for for delays). - snapshotnet.cpp: sleep_for swapped. - DoS_tests.cpp: timing harness uses steady_clock. - Skipped: rpcdump.cpp (boost::posix_time::time_input_facet has no clean std::get_time equivalent) and qt/qtipcserver.cpp (locked to boost::posix_time by boost::interprocess::message_queue::timed_receive). Other housekeeping: - Dropped unnecessary "using namespace boost;" from txdb-leveldb.cpp, txdb-rocksdb.cpp, walletdb.cpp, db.cpp (verified no unqualified boost names in those TUs). - Removed unused extern declaration for clearwallettransactions. Build fixes for non-unity builds on MinGW64/GCC 15: - net.cpp: dropped stale #include "irc.h". - addrman.cpp + main.cpp: explicit <cmath> include for sqrt/pow (was arriving transitively via boost headers). - rpcblockchain.cpp + init.cpp: defensive #undef STRICT/ADVISORY/PERMISSIVE since windows.h macros collide with the Checkpoints:: enum values when std headers reorder include flow. - tor_embed_hooks.cpp: triangles_tor_check_interrupted now polls fShutdown instead of boost::this_thread::interruption_requested (we never used boost interruption — the hook was always effectively a no-op). - snapshotnet.cpp: fs::remove error handle uses std::error_code. - serialize.h: added <ios> for std::ios::badbit/failbit (was relying on transitive include via boost). Note: unity builds currently fail on this branch due to std::byte (C++17) colliding with COM 'byte' typedef from shlobj.h when 'using namespace std;' from earlier files in the unity slice leaks into util.cpp's parse of shlobj.h. Build with -DENABLE_UNITY_BUILD=OFF (the default). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
182 lines
3.9 KiB
C++
182 lines
3.9 KiB
C++
// Copyright (c) 2012-2013 The Bitcoin developers
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef TRIANGLES_CHECKQUEUE_H
|
|
#define TRIANGLES_CHECKQUEUE_H
|
|
|
|
#include <algorithm>
|
|
#include <deque>
|
|
#include <vector>
|
|
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
#include <thread>
|
|
|
|
template<typename T>
|
|
class CCheckQueue
|
|
{
|
|
private:
|
|
std::mutex mutex;
|
|
std::condition_variable condWorker;
|
|
std::condition_variable condMaster;
|
|
|
|
std::deque<T> queue;
|
|
unsigned int nIdle;
|
|
unsigned int nTotal;
|
|
bool fAllOk;
|
|
unsigned int nTodo;
|
|
bool fQuit;
|
|
|
|
unsigned int nBatchSize;
|
|
|
|
bool Loop(bool fMaster)
|
|
{
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
if (!fMaster)
|
|
nTotal++;
|
|
nIdle++;
|
|
|
|
bool fOk = true;
|
|
|
|
for (;;)
|
|
{
|
|
while (queue.empty())
|
|
{
|
|
if (fQuit)
|
|
{
|
|
nIdle--;
|
|
if (!fMaster)
|
|
nTotal--;
|
|
return false;
|
|
}
|
|
if (fMaster && nTodo == 0)
|
|
{
|
|
bool fRet = fAllOk;
|
|
nIdle--;
|
|
return fRet;
|
|
}
|
|
if (fMaster)
|
|
condMaster.wait(lock);
|
|
else
|
|
condWorker.wait(lock);
|
|
}
|
|
|
|
unsigned int nNow = std::max(1U, std::min((unsigned int)queue.size() / (nTotal + 1), nBatchSize));
|
|
std::vector<T> vChecks(nNow);
|
|
for (unsigned int i = 0; i < nNow; i++)
|
|
{
|
|
vChecks[i].swap(queue.front());
|
|
queue.pop_front();
|
|
}
|
|
nIdle--;
|
|
lock.unlock();
|
|
|
|
for (unsigned int i = 0; i < vChecks.size(); i++)
|
|
{
|
|
if (fOk)
|
|
fOk = vChecks[i]();
|
|
}
|
|
vChecks.clear();
|
|
|
|
lock.lock();
|
|
nIdle++;
|
|
nTodo -= nNow;
|
|
if (!fOk)
|
|
fAllOk = false;
|
|
|
|
if (nTodo == 0)
|
|
condMaster.notify_one();
|
|
}
|
|
}
|
|
|
|
public:
|
|
CCheckQueue(unsigned int nBatchSizeIn = 128)
|
|
: nIdle(0), nTotal(0), fAllOk(true), nTodo(0), fQuit(false),
|
|
nBatchSize(nBatchSizeIn) {}
|
|
|
|
void Thread()
|
|
{
|
|
Loop(false);
|
|
}
|
|
|
|
void StartBatch()
|
|
{
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
fAllOk = true;
|
|
nTodo = 0;
|
|
}
|
|
|
|
void Add(std::vector<T>& vChecks)
|
|
{
|
|
if (vChecks.empty())
|
|
return;
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
for (typename std::vector<T>::iterator it = vChecks.begin(); it != vChecks.end(); ++it)
|
|
{
|
|
queue.push_back(T());
|
|
queue.back().swap(*it);
|
|
}
|
|
nTodo += vChecks.size();
|
|
if (vChecks.size() == 1)
|
|
condWorker.notify_one();
|
|
else
|
|
condWorker.notify_all();
|
|
}
|
|
|
|
bool Wait()
|
|
{
|
|
return Loop(true);
|
|
}
|
|
|
|
void Quit()
|
|
{
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
fQuit = true;
|
|
condWorker.notify_all();
|
|
condMaster.notify_all();
|
|
}
|
|
};
|
|
|
|
template<typename T>
|
|
class CCheckQueueControl
|
|
{
|
|
private:
|
|
CCheckQueue<T>* pqueue;
|
|
bool fDone;
|
|
|
|
CCheckQueueControl(const CCheckQueueControl&);
|
|
CCheckQueueControl& operator=(const CCheckQueueControl&);
|
|
|
|
public:
|
|
CCheckQueueControl(CCheckQueue<T>* pqueueIn)
|
|
: pqueue(pqueueIn), fDone(false)
|
|
{
|
|
if (pqueue)
|
|
pqueue->StartBatch();
|
|
}
|
|
|
|
bool Wait()
|
|
{
|
|
if (!pqueue || fDone)
|
|
return true;
|
|
fDone = true;
|
|
return pqueue->Wait();
|
|
}
|
|
|
|
void Add(std::vector<T>& vChecks)
|
|
{
|
|
if (pqueue)
|
|
pqueue->Add(vChecks);
|
|
}
|
|
|
|
~CCheckQueueControl()
|
|
{
|
|
if (!fDone)
|
|
Wait();
|
|
}
|
|
};
|
|
|
|
#endif // TRIANGLES_CHECKQUEUE_H
|