#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+
+#include <mutex>
+
#include "logger.hh"
#include "misc.hh"
#ifndef RECURSOR
#include "statbag.hh"
extern StatBag S;
#endif
-#include "lock.hh"
#include "namespaces.hh"
thread_local Logger::PerThread Logger::t_perThread;
}
}
- static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
- Lock l(&m); // the C++-2011 spec says we need this, and OSX actually does
+ static std::mutex m;
+ std::lock_guard<std::mutex> l(m); // the C++-2011 spec says we need this, and OSX actually does
clog << string(buffer) + prefix + msg <<endl;
#ifndef RECURSOR
mustAccount=true;
#if (OPENSSL_VERSION_NUMBER < 0x1010000fL || (defined LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2090100fL)
/* OpenSSL < 1.1.0 needs support for threading/locking in the calling application. */
-static pthread_mutex_t *openssllocks;
+
+#include "lock.hh"
+static std::vector<std::mutex> openssllocks;
extern "C" {
void openssl_pthreads_locking_callback(int mode, int type, const char *file, int line)
{
if (mode & CRYPTO_LOCK) {
- pthread_mutex_lock(&(openssllocks[type]));
+ openssllocks.at(type).lock();
- }else {
- pthread_mutex_unlock(&(openssllocks[type]));
+ } else {
+ openssllocks.at(type).unlock();
}
}
void openssl_thread_setup()
{
- openssllocks = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
-
- for (int i = 0; i < CRYPTO_num_locks(); i++)
- pthread_mutex_init(&(openssllocks[i]), NULL);
-
- CRYPTO_set_id_callback(openssl_pthreads_id_callback);
- CRYPTO_set_locking_callback(openssl_pthreads_locking_callback);
+ openssllocks = std::vector<std::mutex>(CRYPTO_num_locks());
+ CRYPTO_set_id_callback(&openssl_pthreads_id_callback);
+ CRYPTO_set_locking_callback(&openssl_pthreads_locking_callback);
}
void openssl_thread_cleanup()
{
- CRYPTO_set_locking_callback(NULL);
-
- for (int i=0; i<CRYPTO_num_locks(); i++) {
- pthread_mutex_destroy(&(openssllocks[i]));
- }
-
- OPENSSL_free(openssllocks);
+ CRYPTO_set_locking_callback(nullptr);
+ openssllocks.clear();
}
#ifndef HAVE_RSA_GET0_KEY
vector<string> carbonServers;
{
- Lock l(&g_carbon_config_lock);
+ std::lock_guard<std::mutex> l(g_carbon_config_lock);
stringtok(carbonServers, arg()["carbon-server"], ", ");
namespace_name=arg()["carbon-namespace"];
hostname=arg()["carbon-ourname"];
enum class StatComponent { API, Carbon, RecControl, SNMP };
std::map<std::string, std::string> getAllStatsMap(StatComponent component);
-extern pthread_mutex_t g_carbon_config_lock;
+extern std::mutex g_carbon_config_lock;
std::vector<std::pair<DNSName, uint16_t> >* pleaseGetQueryRing();
std::vector<std::pair<DNSName, uint16_t> >* pleaseGetServfailQueryRing();
std::vector<std::pair<DNSName, uint16_t> >* pleaseGetBogusQueryRing();
#include "secpoll-recursor.hh"
#include "pubsuffix.hh"
#include "namespaces.hh"
-pthread_mutex_t g_carbon_config_lock=PTHREAD_MUTEX_INITIALIZER;
+std::mutex g_carbon_config_lock;
static map<string, const uint32_t*> d_get32bitpointers;
static map<string, const std::atomic<uint64_t>*> d_getatomics;
static map<string, function< uint64_t() > > d_get64bitmembers;
-static pthread_mutex_t d_dynmetricslock = PTHREAD_MUTEX_INITIALIZER;
+static std::mutex d_dynmetricslock;
static map<string, std::atomic<unsigned long>* > d_dynmetrics;
static std::map<StatComponent, std::set<std::string>> s_blacklistedStats;
std::atomic<unsigned long>* getDynMetric(const std::string& str)
{
- Lock l(&d_dynmetricslock);
+ std::lock_guard<std::mutex> l(d_dynmetricslock);
auto f = d_dynmetrics.find(str);
if(f != d_dynmetrics.end())
return f->second;
if(d_get64bitmembers.count(name))
return d_get64bitmembers.find(name)->second();
- Lock l(&d_dynmetricslock);
+ std::lock_guard<std::mutex> l(d_dynmetricslock);
auto f =rplookup(d_dynmetrics, name);
if(f)
return (*f)->load();
}
{
- Lock l(&d_dynmetricslock);
+ std::lock_guard<std::mutex> l(d_dynmetricslock);
for(const auto& a : d_dynmetrics) {
if (blacklistMap.count(a.first) == 0) {
ret.insert({a.first, std::to_string(*a.second)});
template<typename T>
static string doSetCarbonServer(T begin, T end)
{
- Lock l(&g_carbon_config_lock);
+ std::lock_guard<std::mutex> l(g_carbon_config_lock);
if(begin==end) {
::arg().set("carbon-server").clear();
return "cleared carbon-server setting\n";