if (!loadZones && d_hybrid)
return;
- std::lock_guard<std::mutex> l(s_startup_lock);
+ auto lock = std::scoped_lock(s_startup_lock);
setupDNSSEC();
if (s_first == 0) {
<< "' from autoprimary " << ipAddress << endl;
{
- std::lock_guard<std::mutex> l2(s_autosecondary_config_lock);
+ auto lock = std::scoped_lock(s_autosecondary_config_lock);
ofstream c_of(getArg("autoprimary-config").c_str(), std::ios::app);
if (!c_of) {
int retry = 1;
{
- std::lock_guard<std::mutex> l(s_myinitlock);
+ auto lock = std::scoped_lock(s_myinitlock);
if (d_threadCleanup) {
threadcloser.enable();
}
bool opened = false;
if (s_first) {
- std::lock_guard<std::mutex> l(s_lmdbStartupLock);
+ auto lock = std::scoped_lock(s_lmdbStartupLock);
if (s_first) {
auto filename = getArg("filename");
}
line.append(1, '\n');
- std::lock_guard<std::mutex> l(g_guardian_lock);
+ auto lock = std::scoped_lock(g_guardian_lock);
try {
writen2(g_fd1[1], line.c_str(), line.size() + 1);
d_stopped = true;
{
- std::lock_guard<std::mutex> tl(connectLock);
+ auto tlock = std::scoped_lock(connectLock);
auto slock = mplexer.lock();
for (auto& fd : sockets) {
if (g_dohStatesDumpRequested > 0) {
/* just to keep things clean in the output, debug only */
static std::mutex s_lock;
- std::lock_guard<decltype(s_lock)> lck(s_lock);
+ auto lock = std::scoped_lock(s_lock);
if (g_dohStatesDumpRequested > 0) {
/* no race here, we took the lock so it can only be increased in the meantime */
--g_dohStatesDumpRequested;
auto [sender, receiver] = pdns::channel::createObjectQueue<CrossProtocolQuery>(pdns::channel::SenderBlockingMode::SenderNonBlocking, pdns::channel::ReceiverBlockingMode::ReceiverNonBlocking, internalPipeBufferSize);
vinfolog("Adding DoH Client thread");
- std::lock_guard<std::mutex> lock(d_mutex);
+ auto lock = std::scoped_lock(d_mutex);
if (d_numberOfThreads >= d_clientThreads.size()) {
vinfolog("Adding a new DoH client thread would exceed the vector size (%d/%d), skipping. Consider increasing the maximum amount of DoH client threads with setMaxDoHClientThreads() in the configuration.", d_numberOfThreads, d_clientThreads.size());
{
/* just to keep things clean in the output, debug only */
static std::mutex s_lock;
- std::lock_guard<decltype(s_lock)> lck(s_lock);
+ auto lock = std::scoped_lock(s_lock);
if (g_tcpStatesDumpRequested > 0) {
/* no race here, we took the lock so it can only be increased in the meantime */
--g_tcpStatesDumpRequested;
{
// strftime is not thread safe, it can access locale information
static std::mutex mutex;
- auto lock = std::lock_guard(mutex);
+ auto lock = std::scoped_lock(mutex);
if (strftime(buffer.data(), buffer.size(), timeFormat, &localNow) == 0) {
buffer[0] = '\0';
}
{
- std::lock_guard<std::mutex> lg(g_tcpRequestFDsMutex);
+ auto lock = std::scoped_lock(g_tcpRequestFDsMutex);
g_tcpRequestFDs.push({cfd, saddr});
}
g_tcpHandlerCV.notify_one();
}
private:
- std::lock_guard<std::mutex> d_lock;
+ std::scoped_lock<std::mutex> d_lock;
T& d_value;
};
}
private:
- std::lock_guard<std::recursive_mutex> d_lock;
+ std::scoped_lock<std::recursive_mutex> d_lock;
T& d_value;
};
}
private:
- std::lock_guard<std::shared_mutex> d_lock;
+ std::scoped_lock<std::shared_mutex> d_lock;
T& d_value;
};
}
static std::mutex mutex;
- std::lock_guard<std::mutex> lock(mutex); // the C++-2011 spec says we need this, and OSX actually does
+ auto lock = std::scoped_lock(mutex); // the C++-2011 spec says we need this, and OSX actually does
// To avoid issuing multiple syscalls, we write the complete line to clog with a single << call.
// For that we need a buffer allocated, we might want to use writev(2) one day to avoid that.
d_totAllocated += size;
- std::lock_guard<std::mutex> lock(d_mut);
+ auto lock = std::scoped_lock(d_mut);
auto& ent=d_stats[makeBacktrace()];
ent.count++;
ent.sizes[size]++;
__libc_free(ptr);
if(!l_active) {
l_active=true;
- std::lock_guard<std::mutex> lock(d_mut);
+ auto lock = std::scoped_lock(d_mut);
auto f = d_sizes.find(ptr);
if(f != d_sizes.end()) {
d_totAllocated -= f->second;
void MallocTracer::clearAllocators()
{
l_active=true;
- std::lock_guard<std::mutex> lock(d_mut);
+ auto lock = std::scoped_lock(d_mut);
d_stats.clear();
l_active=false;
}
uint64_t getAllocs(const std::string& = std::string()) const { return d_allocs; }
uint64_t getAllocFlux(const std::string& = std::string()) const { return d_allocflux; }
uint64_t getTotAllocated(const std::string& = std::string()) const { return d_totAllocated; }
- uint64_t getNumOut() { std::lock_guard<std::mutex> lock(d_mut); return d_sizes.size(); }
+ uint64_t getNumOut() { std::scoped_lock<std::mutex> lock(d_mut); return d_sizes.size(); }
struct AllocStats
{
int count;
if (format != "%s") {
// strftime is not thread safe, it can access locale information
static std::mutex mutex;
- auto lock = std::lock_guard(mutex);
+ auto lock = std::scoped_lock(mutex);
struct tm theTime // clang-format insists on formatting it like this
{};
len = strftime(buf.data(), buf.size(), format.c_str(), localtime_r(&tval.tv_sec, &theTime));
std::mutex PersistentSBF::d_cachedir_mutex;
-void PersistentSBF::remove_tmp_files(const filesystem::path& path, std::lock_guard<std::mutex>& /* lock */)
+void PersistentSBF::remove_tmp_files(const filesystem::path& path, std::scoped_lock<std::mutex>& /* lock */)
{
Regex file_regex(d_prefix + ".*\\." + bf_suffix + "\\..{8}$");
for (const auto& file : filesystem::directory_iterator(path)) {
bool PersistentSBF::init(bool ignore_pid)
{
auto log = g_slog->withName("nod");
- std::lock_guard<std::mutex> lock(d_cachedir_mutex);
+ std::scoped_lock<std::mutex> lock(d_cachedir_mutex);
if (d_cachedir.length() != 0) {
filesystem::path path(d_cachedir);
try {
}
private:
- void remove_tmp_files(const boost::filesystem::path&, std::lock_guard<std::mutex>&);
+ void remove_tmp_files(const boost::filesystem::path&, std::scoped_lock<std::mutex>&);
LockGuarded<bf::stableBF> d_sbf; // Stable Bloom Filter
std::string d_cachedir;
void broadcastFunction(const pipefunc_t& func)
{
// we do not want the handler and web code to use pipes simultaneously
- std::lock_guard lock(pipeBroadCastMutex);
+ std::scoped_lock lock(pipeBroadCastMutex);
/* This function might be called by the worker with t_id not inited during startup
for the initialization of ACLs and domain maps. After that it should only
}
// we do not want the handler and web code to use pipes simultaneously
- std::lock_guard lock(pipeBroadCastMutex);
+ std::scoped_lock lock(pipeBroadCastMutex);
unsigned int thread = 0;
T ret = T();
ret = serviceMain(startupLog);
{
- std::lock_guard lock(g_doneRunning.mutex);
+ std::scoped_lock lock(g_doneRunning.mutex);
g_doneRunning.done = true;
g_doneRunning.condVar.notify_one();
}
static time_t last = 0;
static ThreadTimes tt;
- std::lock_guard<std::mutex> l(s_mut);
+ auto lock = std::scoped_lock(s_mut);
if (last != time(nullptr)) {
tt = broadcastAccFunction<ThreadTimes>(pleaseGetThreadCPUMsec);
last = time(nullptr);
}
- std::lock_guard<std::mutex> l(s_rfc2136lock); //TODO: i think this lock can be per zone, not for everything
+ auto lock = std::scoped_lock(s_rfc2136lock); //TODO: i think this lock can be per zone, not for everything
g_log<<Logger::Info<<msgPrefix<<"starting transaction."<<endl;
if (!di.backend->startTransaction(packet.qdomainzone, UnknownDomainID)) { // Not giving the domain_id means that we do not delete the existing records.
g_log<<Logger::Error<<msgPrefix<<"Backend for domain "<<packet.qdomainzone<<" does not support transaction. Can't do Update packet."<<endl;
void operator()() const
{
for (size_t idx = 0; idx < 1000; idx++) {
- std::unique_lock<decltype(d_testlock)> lock(d_testlock);
+ auto lock = std::scoped_lock(d_testlock);
++d_value;
}
}
void operator()() const
{
for (size_t idx = 0; idx < 1000; idx++) {
- std::lock_guard<decltype(d_testlock)> lock(d_testlock);
+ auto lock = std::scoped_lock(d_testlock);
++d_value;
}
}
s_backendQueries = S.getPointer("backend-queries");
{
- std::unique_lock<std::mutex> lock(d_mut);
+ std::scoped_lock<std::mutex> lock(d_mut);
d_go = true;
}
d_cond.notify_all();