epee: syncobj: replace shims with Boost classes

a. `critical_section` is functionally identical to a `boost::recursive_mutex`
b. `critical_region_t` is functionally identical to a `boost::unique_lock`
c. remove some vestigial definitons `g_test_dbg_lock_sleep` as a variable
This commit is contained in:
jeffro256 2025-04-01 10:14:28 -05:00
parent 977dedce2c
commit 8af33c71cf
No known key found for this signature in database
GPG key ID: 6F79797A6E392442
5 changed files with 5 additions and 85 deletions

View file

@ -495,7 +495,7 @@ public:
if(is_response)
{//response to some invoke
epee::critical_region_t<decltype(m_invoke_response_handlers_lock)> invoke_response_handlers_guard(m_invoke_response_handlers_lock);
boost::unique_lock invoke_response_handlers_guard(m_invoke_response_handlers_lock);
if(!m_invoke_response_handlers.empty())
{//async call scenario
boost::shared_ptr<invoke_response_handler_base> response_handler = m_invoke_response_handlers.front();

View file

@ -76,84 +76,11 @@ namespace epee
bool m_rised;
};
class critical_region;
using critical_section = boost::recursive_mutex;
class critical_section
{
boost::recursive_mutex m_section;
public:
//to make copy fake!
critical_section(const critical_section& section)
{
}
critical_section()
{
}
~critical_section()
{
}
void lock()
{
m_section.lock();
//EnterCriticalSection( &m_section );
}
void unlock()
{
m_section.unlock();
}
bool tryLock()
{
return m_section.try_lock();
}
// to make copy fake
critical_section& operator=(const critical_section& section)
{
return *this;
}
};
template<class t_lock>
class critical_region_t
{
t_lock& m_locker;
bool m_unlocked;
critical_region_t(const critical_region_t&) {}
public:
critical_region_t(t_lock& cs): m_locker(cs), m_unlocked(false)
{
m_locker.lock();
}
~critical_region_t()
{
unlock();
}
void unlock()
{
if (!m_unlocked)
{
m_locker.unlock();
m_unlocked = true;
}
}
};
#define CRITICAL_REGION_LOCAL(x) {} epee::critical_region_t<decltype(x)> critical_region_var(x)
#define CRITICAL_REGION_BEGIN(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t<decltype(x)> critical_region_var(x)
#define CRITICAL_REGION_LOCAL1(x) {boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t<decltype(x)> critical_region_var1(x)
#define CRITICAL_REGION_BEGIN1(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t<decltype(x)> critical_region_var1(x)
#define CRITICAL_REGION_LOCAL(x) boost::unique_lock critical_region_var(x)
#define CRITICAL_REGION_BEGIN(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); boost::unique_lock critical_region_var(x)
#define CRITICAL_REGION_LOCAL1(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} boost::unique_lock critical_region_var1(x)
#define CRITICAL_REGION_END() }

View file

@ -135,8 +135,6 @@ void cryptonote_protocol_handler_base::handler_response_blocks_now(size_t packet
{
CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out );
network_throttle_manager::get_global_throttle_out().handle_trafic_tcp( packet_size ); // increase counter - global
//epee::critical_region_t<decltype(m_throttle_global_lock)> guard(m_throttle_global_lock); // *** critical ***
//m_throttle_global.m_out.handle_trafic_tcp( packet_size ); // increase counter - global
}
}

View file

@ -43,10 +43,6 @@
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "WalletAPI"
namespace epee {
unsigned int g_test_dbg_lock_sleep = 0;
}
namespace Monero {
WalletManagerImpl::WalletManagerImpl()

View file

@ -51,7 +51,6 @@
using namespace std;
//unsigned int epee::g_test_dbg_lock_sleep = 0;
namespace Consts
{