MXS-2067: Remove spinlock.hh
Replaced the C++ versions with standard library mutexes.
This commit is contained in:
@ -32,7 +32,6 @@
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/router.h>
|
||||
#include <maxscale/spinlock.hh>
|
||||
#include <maxscale/users.h>
|
||||
|
||||
#include "internal/config.hh"
|
||||
@ -46,7 +45,7 @@ typedef std::vector<std::string> StringVector;
|
||||
|
||||
using std::tie;
|
||||
|
||||
static mxs::SpinLock crt_lock;
|
||||
static std::mutex crt_lock;
|
||||
|
||||
#define RUNTIME_ERRMSG_BUFSIZE 512
|
||||
thread_local char runtime_errmsg[RUNTIME_ERRMSG_BUFSIZE];
|
||||
@ -133,7 +132,7 @@ static std::pair<bool, MXS_CONFIG_PARAMETER*> load_defaults(const char* name,
|
||||
|
||||
bool runtime_link_server(SERVER* server, const char* target)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
bool rval = false;
|
||||
Service* service = service_internal_find(target);
|
||||
@ -177,7 +176,7 @@ bool runtime_link_server(SERVER* server, const char* target)
|
||||
|
||||
bool runtime_unlink_server(SERVER* server, const char* target)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
bool rval = false;
|
||||
Service* service = service_internal_find(target);
|
||||
@ -211,7 +210,7 @@ bool runtime_create_server(const char* name,
|
||||
const char* protocol,
|
||||
const char* authenticator)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
bool rval = false;
|
||||
|
||||
if (server_find_by_unique_name(name) == NULL)
|
||||
@ -274,7 +273,7 @@ bool runtime_create_server(const char* name,
|
||||
|
||||
bool runtime_destroy_server(SERVER* server)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
bool rval = false;
|
||||
|
||||
if (service_server_in_use(server) || monitor_server_in_use(server))
|
||||
@ -370,7 +369,7 @@ bool runtime_enable_server_ssl(SERVER* server,
|
||||
|
||||
if (key && cert && ca)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
SSL_LISTENER* ssl = create_ssl(server->name, key, cert, ca, version, depth, verify);
|
||||
|
||||
if (ssl)
|
||||
@ -465,7 +464,7 @@ bool runtime_alter_server(SERVER* server, const char* key, const char* value)
|
||||
return false;
|
||||
}
|
||||
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
server_set_parameter(server, key, value);
|
||||
|
||||
if (strcmp(key, CN_ADDRESS) == 0)
|
||||
@ -557,7 +556,7 @@ bool do_alter_monitor(MXS_MONITOR* monitor, const char* key, const char* value,
|
||||
return false;
|
||||
}
|
||||
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
if (restart_monitor)
|
||||
{
|
||||
@ -671,7 +670,7 @@ bool runtime_alter_service(Service* service, const char* zKey, const char* zValu
|
||||
return false;
|
||||
}
|
||||
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
bool rval = true;
|
||||
|
||||
if (service->is_basic_parameter(key))
|
||||
@ -728,7 +727,7 @@ bool runtime_alter_maxscale(const char* name, const char* value)
|
||||
std::string key = name;
|
||||
bool rval = false;
|
||||
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
if (key == CN_AUTH_CONNECT_TIMEOUT)
|
||||
{
|
||||
@ -927,7 +926,7 @@ bool runtime_create_listener(Service* service,
|
||||
unsigned short u_port = atoi(port);
|
||||
bool rval = false;
|
||||
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
if (!serviceHasListener(service, name, proto, addr, u_port))
|
||||
{
|
||||
@ -997,7 +996,7 @@ bool runtime_destroy_listener(Service* service, const char* name)
|
||||
char filename[PATH_MAX];
|
||||
snprintf(filename, sizeof(filename), "%s/%s.cnf", get_config_persistdir(), name);
|
||||
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
if (unlink(filename) == -1)
|
||||
{
|
||||
@ -1037,7 +1036,7 @@ bool runtime_destroy_listener(Service* service, const char* name)
|
||||
|
||||
bool runtime_create_monitor(const char* name, const char* module)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
bool rval = false;
|
||||
|
||||
if (monitor_find(name) == NULL)
|
||||
@ -1089,7 +1088,7 @@ bool runtime_create_monitor(const char* name, const char* module)
|
||||
|
||||
bool runtime_create_filter(const char* name, const char* module, MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
bool rval = false;
|
||||
|
||||
if (!filter_find(name))
|
||||
@ -1139,7 +1138,7 @@ bool runtime_destroy_filter(const SFilterDef& filter)
|
||||
{
|
||||
mxb_assert(filter);
|
||||
bool rval = false;
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
if (filter_can_be_destroyed(filter))
|
||||
{
|
||||
@ -1158,7 +1157,7 @@ bool runtime_destroy_filter(const SFilterDef& filter)
|
||||
|
||||
static bool runtime_create_service(const char* name, const char* router, MXS_CONFIG_PARAMETER* params)
|
||||
{
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
bool rval = false;
|
||||
|
||||
if (service_internal_find(name) == NULL)
|
||||
@ -1207,7 +1206,7 @@ static bool runtime_create_service(const char* name, const char* router, MXS_CON
|
||||
bool runtime_destroy_service(Service* service)
|
||||
{
|
||||
bool rval = false;
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
mxb_assert(service && service->active);
|
||||
|
||||
if (service_can_be_destroyed(service))
|
||||
@ -1231,7 +1230,7 @@ bool runtime_destroy_monitor(MXS_MONITOR* monitor)
|
||||
char filename[PATH_MAX];
|
||||
snprintf(filename, sizeof(filename), "%s/%s.cnf", get_config_persistdir(), monitor->name);
|
||||
|
||||
mxs::SpinLockGuard guard(crt_lock);
|
||||
std::lock_guard<std::mutex> guard(crt_lock);
|
||||
|
||||
if (unlink(filename) == -1 && errno != ENOENT)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include <maxbase/semaphore.h>
|
||||
#include <maxscale/alloc.h>
|
||||
@ -27,7 +28,6 @@
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/query_classifier.h>
|
||||
#include <maxscale/spinlock.h>
|
||||
#include <maxscale/spinlock.hh>
|
||||
|
||||
/**
|
||||
* @file housekeeper.cc Provide a mechanism to run periodic tasks
|
||||
@ -117,7 +117,7 @@ private:
|
||||
std::thread m_thread;
|
||||
uint32_t m_running;
|
||||
std::list<Task> m_tasks;
|
||||
mxs::SpinLock m_lock;
|
||||
std::mutex m_lock;
|
||||
|
||||
bool is_running() const
|
||||
{
|
||||
@ -172,7 +172,7 @@ void Housekeeper::run()
|
||||
mxb::atomic::add(&mxs_clock_ticks, 1, mxb::atomic::RELAXED);
|
||||
}
|
||||
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
time_t now = time(0);
|
||||
auto it = m_tasks.begin();
|
||||
|
||||
@ -205,19 +205,19 @@ void Housekeeper::stop()
|
||||
|
||||
void Housekeeper::add(const Task& task)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
m_tasks.push_back(task);
|
||||
}
|
||||
|
||||
void Housekeeper::remove(std::string name)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
m_tasks.remove_if(Task::NameMatch(name));
|
||||
}
|
||||
|
||||
void Housekeeper::print_tasks(DCB* pDcb)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
dcb_printf(pDcb, "%-25s | Type | Frequency | Next Due\n", "Name");
|
||||
dcb_printf(pDcb, "--------------------------+----------+-----------+-------------------------\n");
|
||||
|
||||
@ -235,7 +235,7 @@ json_t* Housekeeper::tasks_json(const char* host)
|
||||
{
|
||||
json_t* arr = json_array();
|
||||
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
|
||||
for (auto ptr = m_tasks.begin(); ptr != m_tasks.end(); ptr++)
|
||||
{
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <maxscale/json_api.h>
|
||||
#include <maxscale/modulecmd.h>
|
||||
#include <maxscale/server.hh>
|
||||
#include <maxscale/spinlock.hh>
|
||||
#include <maxscale/routingworker.hh>
|
||||
|
||||
#include "internal/config_runtime.h"
|
||||
@ -41,8 +40,6 @@ using std::list;
|
||||
using std::map;
|
||||
using std::string;
|
||||
using std::stringstream;
|
||||
using mxs::SpinLock;
|
||||
using mxs::SpinLockGuard;
|
||||
|
||||
Resource::Resource(ResourceCallback cb, int components, ...)
|
||||
: m_cb(cb)
|
||||
@ -1205,7 +1202,6 @@ private:
|
||||
|
||||
static RootResource resources; /**< Core resource set */
|
||||
static ResourceWatcher watcher; /**< Modification watcher */
|
||||
static SpinLock resource_lock;
|
||||
|
||||
static bool request_modifies_data(const string& verb)
|
||||
{
|
||||
|
@ -13,15 +13,15 @@
|
||||
|
||||
#include <maxscale/ccdefs.hh>
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <new>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <maxscale/users.h>
|
||||
#include <maxscale/authenticator.h>
|
||||
#include <maxscale/spinlock.hh>
|
||||
#include <maxscale/log.h>
|
||||
#include <maxscale/jansson.hh>
|
||||
|
||||
@ -67,13 +67,13 @@ public:
|
||||
|
||||
bool add(std::string user, std::string password, user_account_type perm)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
return m_data.insert(std::make_pair(user, UserInfo(password, perm))).second;
|
||||
}
|
||||
|
||||
bool remove(std::string user)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
bool rval = false;
|
||||
UserMap::iterator it = m_data.find(user);
|
||||
|
||||
@ -88,7 +88,7 @@ public:
|
||||
|
||||
bool get(std::string user, UserInfo* output = NULL) const
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
UserMap::const_iterator it = m_data.find(user);
|
||||
bool rval = false;
|
||||
|
||||
@ -112,7 +112,7 @@ public:
|
||||
|
||||
bool check_permissions(std::string user, user_account_type perm) const
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
UserMap::const_iterator it = m_data.find(user);
|
||||
bool rval = false;
|
||||
|
||||
@ -126,7 +126,7 @@ public:
|
||||
|
||||
bool set_permissions(std::string user, user_account_type perm)
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
UserMap::iterator it = m_data.find(user);
|
||||
bool rval = false;
|
||||
|
||||
@ -141,7 +141,7 @@ public:
|
||||
|
||||
json_t* diagnostic_json() const
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
json_t* rval = json_array();
|
||||
|
||||
for (UserMap::const_iterator it = m_data.begin(); it != m_data.end(); it++)
|
||||
@ -157,7 +157,7 @@ public:
|
||||
|
||||
void diagnostic(DCB* dcb) const
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
if (m_data.size())
|
||||
{
|
||||
const char* sep = "";
|
||||
@ -178,14 +178,14 @@ public:
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
return m_data.size() > 0;
|
||||
}
|
||||
|
||||
json_t* to_json() const
|
||||
{
|
||||
json_t* arr = json_array();
|
||||
mxs::SpinLockGuard guard(m_lock);
|
||||
std::lock_guard<std::mutex> guard(m_lock);
|
||||
|
||||
for (UserMap::const_iterator it = m_data.begin(); it != m_data.end(); it++)
|
||||
{
|
||||
@ -241,8 +241,8 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
mxs::SpinLock m_lock;
|
||||
UserMap m_data;
|
||||
mutable std::mutex m_lock;
|
||||
UserMap m_data;
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user