#include <fstream>
#include <yaml-cpp/yaml.h>
-pthread_rwlock_t GeoIPBackend::s_state_lock=PTHREAD_RWLOCK_INITIALIZER;
+ReadWriteLock GeoIPBackend::s_state_lock;
struct GeoIPDNSResourceRecord: DNSResourceRecord {
int weight;
bool unpublishDomainKey(const DNSName& name, unsigned int id) override;
private:
- static pthread_rwlock_t s_state_lock;
+ static ReadWriteLock s_state_lock;
void initialize();
string format2str(string format, const Netmask &addr, GeoIPNetmask& gl);
static thread_local MySQLThreadCloser threadcloser;
bool SMySQL::s_dolog;
-pthread_mutex_t SMySQL::s_myinitlock = PTHREAD_MUTEX_INITIALIZER;
+std::mutex SMySQL::s_myinitlock;
class SMySQLStatement: public SSqlStatement
{
{
int retry=1;
- Lock l(&s_myinitlock);
+ std::lock_guard<std::mutex> l(s_myinitlock);
if (d_threadCleanup) {
threadcloser.enable();
}
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
+#include <mutex>
+
#include <mysql.h>
#include "pdns/backends/gsql/ssql.hh"
#include "pdns/utility.hh"
void connect();
static bool s_dolog;
- static pthread_mutex_t s_myinitlock;
+ static std::mutex s_myinitlock;
MYSQL d_db;
std::string d_database;
static string backendname="[TinyDNSBackend] ";
uint32_t TinyDNSBackend::s_lastId;
-pthread_mutex_t TinyDNSBackend::s_domainInfoLock=PTHREAD_MUTEX_INITIALIZER;
+std::mutex TinyDNSBackend::s_domainInfoLock;
TinyDNSBackend::TDI_suffix_t TinyDNSBackend::s_domainInfo;
vector<string> TinyDNSBackend::getLocations()
}
void TinyDNSBackend::getUpdatedMasters(vector<DomainInfo>* retDomains) {
- Lock l(&s_domainInfoLock); //TODO: We could actually lock less if we do it per suffix.
+ std::lock_guard<std::mutex> l(s_domainInfoLock); //TODO: We could actually lock less if we do it per suffix.
if (! s_domainInfo.count(d_suffix)) {
TDI_t tmp;
}
void TinyDNSBackend::setNotified(uint32_t id, uint32_t serial) {
- Lock l(&s_domainInfoLock);
+ std::lock_guard<std::mutex> l(s_domainInfoLock);
if (!s_domainInfo.count(d_suffix)) {
throw PDNSException("Can't get list of domains to set the serial.");
}
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
+#include <mutex>
using namespace ::boost;
using namespace ::boost::multi_index;
string d_suffix;
// Statics
- static pthread_mutex_t s_domainInfoLock;
+ static std::mutex s_domainInfoLock;
static TDI_suffix_t s_domainInfo;
static uint32_t s_lastId; // used to give a domain an id.
};
_exit(1);
}
-static void* dummyThread(void *)
+static void dummyThread()
{
- void* ignore=0;
- pthread_exit(ignore);
}
static void triggerLoadOfLibraries()
{
- pthread_t tid;
- pthread_create(&tid, 0, dummyThread, 0);
- void* res;
- pthread_join(tid, &res);
+ std::thread dummy(dummyThread);
+ dummy.join();
}
void mainthread()
#include <sys/types.h>
#include <sys/un.h>
#include <dlfcn.h>
-#include <pthread.h>
#include <unistd.h>
#include <boost/algorithm/string.hpp>
#include <fcntl.h>
#include <unistd.h>
#include <boost/algorithm/string.hpp>
+#include <thread>
+
#include "misc.hh"
#include "dns.hh"
#include "arguments.hh"
void DynListener::go()
{
d_ppid=getpid();
- pthread_create(&d_tid,0,&DynListener::theListenerHelper,this);
-}
-
-void *DynListener::theListenerHelper(void *p)
-{
- setThreadName("pdns/ctrlListen");
- DynListener *us=static_cast<DynListener *>(p);
- us->theListener();
- g_log<<Logger::Error<<"Control listener aborted, please file a bug!"<<endl;
- return 0;
+ std::thread listener(std::bind(&DynListener::theListener,this));
+ listener.detach();
}
string DynListener::getLine()
void DynListener::theListener()
{
+ setThreadName("pdns/ctrlListen");
+
try {
signal(SIGPIPE,SIG_IGN);
#pragma once
#include <string>
#include <vector>
-#include <pthread.h>
#include <sys/types.h>
#include <errno.h>
#include <iostream>
~DynListener();
void go();
void theListener();
- static void *theListenerHelper(void *p);
typedef string g_funk_t(const vector<string> &parts, Utility::pid_t ppid); // guido!
typedef struct { g_funk_t *func; string args; string usage; } g_funkwithusage_t;
NetmaskGroup d_tcprange;
int d_s{-1};
int d_client{-1};
- pthread_t d_tid{0};
bool d_nonlocal;
bool d_tcp{false};
pid_t d_ppid{0};
BOOST_AUTO_TEST_SUITE(test_lock_hh)
-static std::vector<std::unique_ptr<pthread_rwlock_t> > g_locks;
+static std::vector<ReadWriteLock> g_locks(1000);
static void lthread()
{
std::vector<ReadLock> rlocks;
for(auto& pp : g_locks)
- rlocks.emplace_back(&*pp);
+ rlocks.emplace_back(pp);
}
BOOST_AUTO_TEST_CASE(test_pdns_lock)
{
- for(unsigned int n=0; n < 1000; ++n) {
- auto p = make_unique<pthread_rwlock_t>();
- pthread_rwlock_init(p.get(), 0);
- g_locks.emplace_back(std::move(p));
- }
-
std::vector<ReadLock> rlocks;
for(auto& pp : g_locks)
- rlocks.emplace_back(&*pp);
+ rlocks.emplace_back(pp);
std::thread thr(lthread);
thr.join();
std::vector<WriteLock> wlocks;
for(auto& pp : g_locks)
- wlocks.emplace_back(&*pp);
+ wlocks.emplace_back(pp);
// on macOS, this TryReadLock throws (EDEADLK) instead of simply failing
// so we catch the exception and consider that success for this test
bool gotit = false;
try {
- TryReadLock trl(&*g_locks[0]);
+ TryReadLock trl(g_locks.at(0));
gotit = trl.gotIt();
}
catch(const PDNSException &e) {
wlocks.clear();
{
- TryReadLock trl2(&*g_locks[0]);
+ TryReadLock trl2(g_locks.at(0));
BOOST_CHECK(trl2.gotIt());
}
- for(auto& pp : g_locks) {
- pthread_rwlock_destroy(pp.get());
- }
+ g_locks.clear();
}
BOOST_AUTO_TEST_SUITE_END()