From: Thomas Markwalder Date: Mon, 19 Sep 2022 13:13:09 +0000 (-0400) Subject: [#2507] Replace CriticalSection with mutex lock in stat_cmds X-Git-Tag: Kea-2.3.1~57 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=47d0501ff1c39e14bdb5a7cba5405e4e2d6d31a0;p=thirdparty%2Fkea.git [#2507] Replace CriticalSection with mutex lock in stat_cmds src/hooks/dhcp/stat_cmds/stat_cmds.cc StatCmds::statLease4GetHandler(CalloutHandle& handle) StatCmds::statLease6GetHandler(CalloutHandle& handle) - removed MultiThreadingCriticalSection instance src/lib/dhcpsrv/memfile_lease_mgr.cc Memfile_LeaseMgr::startLeaseStatsQuery4() Memfile_LeaseMgr::startSubnetLeaseStatsQuery4) Memfile_LeaseMgr::startLeaseStatsQuery6() Memfile_LeaseMgr::startSubnetLeaseStatsQuery6() Memfile_LeaseMgr::startSubnetRangeLeaseStatsQuery6() - lock mutex when runninng in MT --- diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds.cc b/src/hooks/dhcp/stat_cmds/stat_cmds.cc index 8950bc928f..c40deca3a0 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds.cc +++ b/src/hooks/dhcp/stat_cmds/stat_cmds.cc @@ -718,7 +718,6 @@ int StatCmds::statLease4GetHandler(CalloutHandle& handle) { try { LeaseStatCmdsImpl impl; - MultiThreadingCriticalSection cs; return (impl.statLease4GetHandler(handle)); } catch (const std::exception& ex) { @@ -732,7 +731,6 @@ int StatCmds::statLease6GetHandler(CalloutHandle& handle) { try { LeaseStatCmdsImpl impl; - MultiThreadingCriticalSection cs; return (impl.statLease6GetHandler(handle)); } catch (const std::exception& ex) { diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index afb3259840..9352cf9746 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -1990,14 +1990,26 @@ Memfile_LeaseMgr::lfcExecute(boost::shared_ptr& lease_file) { LeaseStatsQueryPtr Memfile_LeaseMgr::startLeaseStatsQuery4() { LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery4(storage4_)); - query->start(); + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(*mutex_); + query->start(); + } else { + query->start(); + } + return(query); } LeaseStatsQueryPtr Memfile_LeaseMgr::startSubnetLeaseStatsQuery4(const SubnetID& subnet_id) { LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery4(storage4_, subnet_id)); - query->start(); + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(*mutex_); + query->start(); + } else { + query->start(); + } + return(query); } @@ -2006,21 +2018,39 @@ Memfile_LeaseMgr::startSubnetRangeLeaseStatsQuery4(const SubnetID& first_subnet_ const SubnetID& last_subnet_id) { LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery4(storage4_, first_subnet_id, last_subnet_id)); - query->start(); + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(*mutex_); + query->start(); + } else { + query->start(); + } + return(query); } LeaseStatsQueryPtr Memfile_LeaseMgr::startLeaseStatsQuery6() { LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery6(storage6_)); - query->start(); + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(*mutex_); + query->start(); + } else { + query->start(); + } + return(query); } LeaseStatsQueryPtr Memfile_LeaseMgr::startSubnetLeaseStatsQuery6(const SubnetID& subnet_id) { LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery6(storage6_, subnet_id)); - query->start(); + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(*mutex_); + query->start(); + } else { + query->start(); + } + return(query); } @@ -2029,7 +2059,13 @@ Memfile_LeaseMgr::startSubnetRangeLeaseStatsQuery6(const SubnetID& first_subnet_ const SubnetID& last_subnet_id) { LeaseStatsQueryPtr query(new MemfileLeaseStatsQuery6(storage6_, first_subnet_id, last_subnet_id)); - query->start(); + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard lock(*mutex_); + query->start(); + } else { + query->start(); + } + return(query); }