MXS-2067: Remove spinlock.hh
Replaced the C++ versions with standard library mutexes.
This commit is contained in:
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 MariaDB Corporation Ab
|
|
||||||
*
|
|
||||||
* Use of this software is governed by the Business Source License included
|
|
||||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
||||||
*
|
|
||||||
* Change Date: 2022-01-01
|
|
||||||
*
|
|
||||||
* On the date above, in accordance with the Business Source License, use
|
|
||||||
* of this software will be governed by version 2 or later of the General
|
|
||||||
* Public License.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <maxscale/ccdefs.hh>
|
|
||||||
#include <maxscale/spinlock.h>
|
|
||||||
|
|
||||||
namespace maxscale
|
|
||||||
{
|
|
||||||
|
|
||||||
class SpinLockGuard;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @class SpinLock spinlock.hh <maxscale/spinlock.hh>
|
|
||||||
*
|
|
||||||
* The class SpinLock is a simple class that wraps a regular SPINLOCK
|
|
||||||
* and provides equivalent functionality.
|
|
||||||
*/
|
|
||||||
class SpinLock
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class SpinLockGuard;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a spinlock.
|
|
||||||
*/
|
|
||||||
SpinLock()
|
|
||||||
{
|
|
||||||
spinlock_init(&m_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
~SpinLock()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Acquires the spinlock.
|
|
||||||
*/
|
|
||||||
void acquire() const
|
|
||||||
{
|
|
||||||
spinlock_acquire(&m_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Releases the spinlock.
|
|
||||||
*/
|
|
||||||
void release() const
|
|
||||||
{
|
|
||||||
spinlock_release(&m_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
SpinLock(const SpinLock&) /* = delete */;
|
|
||||||
SpinLock& operator=(const SpinLock&) /* = delete */;
|
|
||||||
|
|
||||||
private:
|
|
||||||
mutable SPINLOCK m_lock;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @class SpinLockGuard spinlock.hh <maxscale/spinlock.hh>
|
|
||||||
*
|
|
||||||
* The class SpinLockGuard is a spinlock wrapper that provides a RAII-style
|
|
||||||
* mechanism for owning a spinlock for the duration of a scoped block. When
|
|
||||||
* a SpinLockGuard object is created, it attempts to take ownership of the
|
|
||||||
* spinlock it is given. When control leaves the scope in which the
|
|
||||||
* SpinLockGuard object was created, the SpinLockGuard is destructed and the
|
|
||||||
* mutex is released.
|
|
||||||
*/
|
|
||||||
class SpinLockGuard
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Creates the guard and locks the provided lock.
|
|
||||||
*
|
|
||||||
* @param lock The spinlock to lock.
|
|
||||||
*/
|
|
||||||
SpinLockGuard(const SPINLOCK& lock)
|
|
||||||
: m_lock(lock)
|
|
||||||
{
|
|
||||||
spinlock_acquire(&m_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the guard and locks the provided lock.
|
|
||||||
*
|
|
||||||
* @param lock The spinlock to lock.
|
|
||||||
*/
|
|
||||||
SpinLockGuard(const SpinLock& lock)
|
|
||||||
: m_lock(lock.m_lock)
|
|
||||||
{
|
|
||||||
spinlock_acquire(&m_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys the guard and unlocks the lock that was provided when
|
|
||||||
* the guard was created.
|
|
||||||
*/
|
|
||||||
~SpinLockGuard()
|
|
||||||
{
|
|
||||||
spinlock_release(&m_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
SpinLockGuard(const SpinLockGuard&) /* = delete */;
|
|
||||||
SpinLockGuard& operator=(const SpinLockGuard&) /* = delete */;
|
|
||||||
|
|
||||||
const SPINLOCK& m_lock;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -32,7 +32,6 @@
|
|||||||
#include <maxscale/json_api.h>
|
#include <maxscale/json_api.h>
|
||||||
#include <maxscale/paths.h>
|
#include <maxscale/paths.h>
|
||||||
#include <maxscale/router.h>
|
#include <maxscale/router.h>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
#include <maxscale/users.h>
|
#include <maxscale/users.h>
|
||||||
|
|
||||||
#include "internal/config.hh"
|
#include "internal/config.hh"
|
||||||
@ -46,7 +45,7 @@ typedef std::vector<std::string> StringVector;
|
|||||||
|
|
||||||
using std::tie;
|
using std::tie;
|
||||||
|
|
||||||
static mxs::SpinLock crt_lock;
|
static std::mutex crt_lock;
|
||||||
|
|
||||||
#define RUNTIME_ERRMSG_BUFSIZE 512
|
#define RUNTIME_ERRMSG_BUFSIZE 512
|
||||||
thread_local char runtime_errmsg[RUNTIME_ERRMSG_BUFSIZE];
|
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)
|
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;
|
bool rval = false;
|
||||||
Service* service = service_internal_find(target);
|
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)
|
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;
|
bool rval = false;
|
||||||
Service* service = service_internal_find(target);
|
Service* service = service_internal_find(target);
|
||||||
@ -211,7 +210,7 @@ bool runtime_create_server(const char* name,
|
|||||||
const char* protocol,
|
const char* protocol,
|
||||||
const char* authenticator)
|
const char* authenticator)
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
if (server_find_by_unique_name(name) == NULL)
|
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)
|
bool runtime_destroy_server(SERVER* server)
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
if (service_server_in_use(server) || monitor_server_in_use(server))
|
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)
|
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);
|
SSL_LISTENER* ssl = create_ssl(server->name, key, cert, ca, version, depth, verify);
|
||||||
|
|
||||||
if (ssl)
|
if (ssl)
|
||||||
@ -465,7 +464,7 @@ bool runtime_alter_server(SERVER* server, const char* key, const char* value)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
server_set_parameter(server, key, value);
|
server_set_parameter(server, key, value);
|
||||||
|
|
||||||
if (strcmp(key, CN_ADDRESS) == 0)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
|
|
||||||
if (restart_monitor)
|
if (restart_monitor)
|
||||||
{
|
{
|
||||||
@ -671,7 +670,7 @@ bool runtime_alter_service(Service* service, const char* zKey, const char* zValu
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
bool rval = true;
|
bool rval = true;
|
||||||
|
|
||||||
if (service->is_basic_parameter(key))
|
if (service->is_basic_parameter(key))
|
||||||
@ -728,7 +727,7 @@ bool runtime_alter_maxscale(const char* name, const char* value)
|
|||||||
std::string key = name;
|
std::string key = name;
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
|
|
||||||
if (key == CN_AUTH_CONNECT_TIMEOUT)
|
if (key == CN_AUTH_CONNECT_TIMEOUT)
|
||||||
{
|
{
|
||||||
@ -927,7 +926,7 @@ bool runtime_create_listener(Service* service,
|
|||||||
unsigned short u_port = atoi(port);
|
unsigned short u_port = atoi(port);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
|
|
||||||
if (!serviceHasListener(service, name, proto, addr, u_port))
|
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];
|
char filename[PATH_MAX];
|
||||||
snprintf(filename, sizeof(filename), "%s/%s.cnf", get_config_persistdir(), name);
|
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)
|
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)
|
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;
|
bool rval = false;
|
||||||
|
|
||||||
if (monitor_find(name) == NULL)
|
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)
|
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;
|
bool rval = false;
|
||||||
|
|
||||||
if (!filter_find(name))
|
if (!filter_find(name))
|
||||||
@ -1139,7 +1138,7 @@ bool runtime_destroy_filter(const SFilterDef& filter)
|
|||||||
{
|
{
|
||||||
mxb_assert(filter);
|
mxb_assert(filter);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
|
|
||||||
if (filter_can_be_destroyed(filter))
|
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)
|
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;
|
bool rval = false;
|
||||||
|
|
||||||
if (service_internal_find(name) == NULL)
|
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 runtime_destroy_service(Service* service)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
mxs::SpinLockGuard guard(crt_lock);
|
std::lock_guard<std::mutex> guard(crt_lock);
|
||||||
mxb_assert(service && service->active);
|
mxb_assert(service && service->active);
|
||||||
|
|
||||||
if (service_can_be_destroyed(service))
|
if (service_can_be_destroyed(service))
|
||||||
@ -1231,7 +1230,7 @@ bool runtime_destroy_monitor(MXS_MONITOR* monitor)
|
|||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
snprintf(filename, sizeof(filename), "%s/%s.cnf", get_config_persistdir(), monitor->name);
|
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)
|
if (unlink(filename) == -1 && errno != ENOENT)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <maxbase/semaphore.h>
|
#include <maxbase/semaphore.h>
|
||||||
#include <maxscale/alloc.h>
|
#include <maxscale/alloc.h>
|
||||||
@ -27,7 +28,6 @@
|
|||||||
#include <maxscale/json_api.h>
|
#include <maxscale/json_api.h>
|
||||||
#include <maxscale/query_classifier.h>
|
#include <maxscale/query_classifier.h>
|
||||||
#include <maxscale/spinlock.h>
|
#include <maxscale/spinlock.h>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file housekeeper.cc Provide a mechanism to run periodic tasks
|
* @file housekeeper.cc Provide a mechanism to run periodic tasks
|
||||||
@ -117,7 +117,7 @@ private:
|
|||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
uint32_t m_running;
|
uint32_t m_running;
|
||||||
std::list<Task> m_tasks;
|
std::list<Task> m_tasks;
|
||||||
mxs::SpinLock m_lock;
|
std::mutex m_lock;
|
||||||
|
|
||||||
bool is_running() const
|
bool is_running() const
|
||||||
{
|
{
|
||||||
@ -172,7 +172,7 @@ void Housekeeper::run()
|
|||||||
mxb::atomic::add(&mxs_clock_ticks, 1, mxb::atomic::RELAXED);
|
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);
|
time_t now = time(0);
|
||||||
auto it = m_tasks.begin();
|
auto it = m_tasks.begin();
|
||||||
|
|
||||||
@ -205,19 +205,19 @@ void Housekeeper::stop()
|
|||||||
|
|
||||||
void Housekeeper::add(const Task& task)
|
void Housekeeper::add(const Task& task)
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
m_tasks.push_back(task);
|
m_tasks.push_back(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Housekeeper::remove(std::string name)
|
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));
|
m_tasks.remove_if(Task::NameMatch(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Housekeeper::print_tasks(DCB* pDcb)
|
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, "%-25s | Type | Frequency | Next Due\n", "Name");
|
||||||
dcb_printf(pDcb, "--------------------------+----------+-----------+-------------------------\n");
|
dcb_printf(pDcb, "--------------------------+----------+-----------+-------------------------\n");
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ json_t* Housekeeper::tasks_json(const char* host)
|
|||||||
{
|
{
|
||||||
json_t* arr = json_array();
|
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++)
|
for (auto ptr = m_tasks.begin(); ptr != m_tasks.end(); ptr++)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -24,7 +24,6 @@
|
|||||||
#include <maxscale/json_api.h>
|
#include <maxscale/json_api.h>
|
||||||
#include <maxscale/modulecmd.h>
|
#include <maxscale/modulecmd.h>
|
||||||
#include <maxscale/server.hh>
|
#include <maxscale/server.hh>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
#include <maxscale/routingworker.hh>
|
#include <maxscale/routingworker.hh>
|
||||||
|
|
||||||
#include "internal/config_runtime.h"
|
#include "internal/config_runtime.h"
|
||||||
@ -41,8 +40,6 @@ using std::list;
|
|||||||
using std::map;
|
using std::map;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
using mxs::SpinLock;
|
|
||||||
using mxs::SpinLockGuard;
|
|
||||||
|
|
||||||
Resource::Resource(ResourceCallback cb, int components, ...)
|
Resource::Resource(ResourceCallback cb, int components, ...)
|
||||||
: m_cb(cb)
|
: m_cb(cb)
|
||||||
@ -1205,7 +1202,6 @@ private:
|
|||||||
|
|
||||||
static RootResource resources; /**< Core resource set */
|
static RootResource resources; /**< Core resource set */
|
||||||
static ResourceWatcher watcher; /**< Modification watcher */
|
static ResourceWatcher watcher; /**< Modification watcher */
|
||||||
static SpinLock resource_lock;
|
|
||||||
|
|
||||||
static bool request_modifies_data(const string& verb)
|
static bool request_modifies_data(const string& verb)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -13,15 +13,15 @@
|
|||||||
|
|
||||||
#include <maxscale/ccdefs.hh>
|
#include <maxscale/ccdefs.hh>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <mutex>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <unordered_map>
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <maxscale/users.h>
|
#include <maxscale/users.h>
|
||||||
#include <maxscale/authenticator.h>
|
#include <maxscale/authenticator.h>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
#include <maxscale/log.h>
|
#include <maxscale/log.h>
|
||||||
#include <maxscale/jansson.hh>
|
#include <maxscale/jansson.hh>
|
||||||
|
|
||||||
@ -67,13 +67,13 @@ public:
|
|||||||
|
|
||||||
bool add(std::string user, std::string password, user_account_type perm)
|
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;
|
return m_data.insert(std::make_pair(user, UserInfo(password, perm))).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool remove(std::string user)
|
bool remove(std::string user)
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
UserMap::iterator it = m_data.find(user);
|
UserMap::iterator it = m_data.find(user);
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ public:
|
|||||||
|
|
||||||
bool get(std::string user, UserInfo* output = NULL) const
|
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);
|
UserMap::const_iterator it = m_data.find(user);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ public:
|
|||||||
|
|
||||||
bool check_permissions(std::string user, user_account_type perm) const
|
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);
|
UserMap::const_iterator it = m_data.find(user);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public:
|
|||||||
|
|
||||||
bool set_permissions(std::string user, user_account_type perm)
|
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);
|
UserMap::iterator it = m_data.find(user);
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ public:
|
|||||||
|
|
||||||
json_t* diagnostic_json() const
|
json_t* diagnostic_json() const
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
json_t* rval = json_array();
|
json_t* rval = json_array();
|
||||||
|
|
||||||
for (UserMap::const_iterator it = m_data.begin(); it != m_data.end(); it++)
|
for (UserMap::const_iterator it = m_data.begin(); it != m_data.end(); it++)
|
||||||
@ -157,7 +157,7 @@ public:
|
|||||||
|
|
||||||
void diagnostic(DCB* dcb) const
|
void diagnostic(DCB* dcb) const
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
if (m_data.size())
|
if (m_data.size())
|
||||||
{
|
{
|
||||||
const char* sep = "";
|
const char* sep = "";
|
||||||
@ -178,14 +178,14 @@ public:
|
|||||||
|
|
||||||
bool empty() const
|
bool empty() const
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
return m_data.size() > 0;
|
return m_data.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_t* to_json() const
|
json_t* to_json() const
|
||||||
{
|
{
|
||||||
json_t* arr = json_array();
|
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++)
|
for (UserMap::const_iterator it = m_data.begin(); it != m_data.end(); it++)
|
||||||
{
|
{
|
||||||
@ -241,7 +241,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mxs::SpinLock m_lock;
|
mutable std::mutex m_lock;
|
||||||
UserMap m_data;
|
UserMap m_data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
9
server/modules/filter/cache/cachemt.cc
vendored
9
server/modules/filter/cache/cachemt.cc
vendored
@ -16,7 +16,6 @@
|
|||||||
#include "storage.hh"
|
#include "storage.hh"
|
||||||
#include "storagefactory.hh"
|
#include "storagefactory.hh"
|
||||||
|
|
||||||
using maxscale::SpinLockGuard;
|
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
|
|
||||||
CacheMT::CacheMT(const std::string& name,
|
CacheMT::CacheMT(const std::string& name,
|
||||||
@ -26,8 +25,6 @@ CacheMT::CacheMT(const std::string& name,
|
|||||||
Storage* pStorage)
|
Storage* pStorage)
|
||||||
: CacheSimple(name, pConfig, rules, sFactory, pStorage)
|
: CacheSimple(name, pConfig, rules, sFactory, pStorage)
|
||||||
{
|
{
|
||||||
spinlock_init(&m_lock_pending);
|
|
||||||
|
|
||||||
MXS_NOTICE("Created multi threaded cache.");
|
MXS_NOTICE("Created multi threaded cache.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,21 +53,21 @@ CacheMT* CacheMT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
|
|||||||
|
|
||||||
json_t* CacheMT::get_info(uint32_t flags) const
|
json_t* CacheMT::get_info(uint32_t flags) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock_pending);
|
std::lock_guard<std::mutex> guard(m_lock_pending);
|
||||||
|
|
||||||
return CacheSimple::do_get_info(flags);
|
return CacheSimple::do_get_info(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CacheMT::must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession)
|
bool CacheMT::must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock_pending);
|
std::lock_guard<std::mutex> guard(m_lock_pending);
|
||||||
|
|
||||||
return do_must_refresh(key, pSession);
|
return do_must_refresh(key, pSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CacheMT::refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession)
|
void CacheMT::refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock_pending);
|
std::lock_guard<std::mutex> guard(m_lock_pending);
|
||||||
|
|
||||||
do_refreshed(key, pSession);
|
do_refreshed(key, pSession);
|
||||||
}
|
}
|
||||||
|
|||||||
6
server/modules/filter/cache/cachemt.hh
vendored
6
server/modules/filter/cache/cachemt.hh
vendored
@ -13,7 +13,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <maxscale/ccdefs.hh>
|
#include <maxscale/ccdefs.hh>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "cachesimple.hh"
|
#include "cachesimple.hh"
|
||||||
|
|
||||||
class CacheMT : public CacheSimple
|
class CacheMT : public CacheSimple
|
||||||
@ -46,5 +48,5 @@ private:
|
|||||||
CacheMT& operator=(const CacheMT&);
|
CacheMT& operator=(const CacheMT&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable SPINLOCK m_lock_pending; // Lock used for protecting 'pending'.
|
mutable std::mutex m_lock_pending; // Lock used for protecting 'pending'.
|
||||||
};
|
};
|
||||||
|
|||||||
20
server/modules/filter/cache/lrustoragemt.cc
vendored
20
server/modules/filter/cache/lrustoragemt.cc
vendored
@ -14,13 +14,9 @@
|
|||||||
#define MXS_MODULE_NAME "cache"
|
#define MXS_MODULE_NAME "cache"
|
||||||
#include "lrustoragemt.hh"
|
#include "lrustoragemt.hh"
|
||||||
|
|
||||||
using maxscale::SpinLockGuard;
|
|
||||||
|
|
||||||
LRUStorageMT::LRUStorageMT(const CACHE_STORAGE_CONFIG& config, Storage* pStorage)
|
LRUStorageMT::LRUStorageMT(const CACHE_STORAGE_CONFIG& config, Storage* pStorage)
|
||||||
: LRUStorage(config, pStorage)
|
: LRUStorage(config, pStorage)
|
||||||
{
|
{
|
||||||
spinlock_init(&m_lock);
|
|
||||||
|
|
||||||
MXS_NOTICE("Created multi threaded LRU storage.");
|
MXS_NOTICE("Created multi threaded LRU storage.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +36,7 @@ LRUStorageMT* LRUStorageMT::create(const CACHE_STORAGE_CONFIG& config, Storage*
|
|||||||
cache_result_t LRUStorageMT::get_info(uint32_t what,
|
cache_result_t LRUStorageMT::get_info(uint32_t what,
|
||||||
json_t** ppInfo) const
|
json_t** ppInfo) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return LRUStorage::do_get_info(what, ppInfo);
|
return LRUStorage::do_get_info(what, ppInfo);
|
||||||
}
|
}
|
||||||
@ -51,49 +47,49 @@ cache_result_t LRUStorageMT::get_value(const CACHE_KEY& key,
|
|||||||
uint32_t hard_ttl,
|
uint32_t hard_ttl,
|
||||||
GWBUF** ppValue) const
|
GWBUF** ppValue) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return do_get_value(key, flags, soft_ttl, hard_ttl, ppValue);
|
return do_get_value(key, flags, soft_ttl, hard_ttl, ppValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::put_value(const CACHE_KEY& key, const GWBUF* pValue)
|
cache_result_t LRUStorageMT::put_value(const CACHE_KEY& key, const GWBUF* pValue)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return do_put_value(key, pValue);
|
return do_put_value(key, pValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::del_value(const CACHE_KEY& key)
|
cache_result_t LRUStorageMT::del_value(const CACHE_KEY& key)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return do_del_value(key);
|
return do_del_value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::get_head(CACHE_KEY* pKey, GWBUF** ppHead) const
|
cache_result_t LRUStorageMT::get_head(CACHE_KEY* pKey, GWBUF** ppHead) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return LRUStorage::do_get_head(pKey, ppHead);
|
return LRUStorage::do_get_head(pKey, ppHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::get_tail(CACHE_KEY* pKey, GWBUF** ppTail) const
|
cache_result_t LRUStorageMT::get_tail(CACHE_KEY* pKey, GWBUF** ppTail) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return LRUStorage::do_get_tail(pKey, ppTail);
|
return LRUStorage::do_get_tail(pKey, ppTail);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::get_size(uint64_t* pSize) const
|
cache_result_t LRUStorageMT::get_size(uint64_t* pSize) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return LRUStorage::do_get_size(pSize);
|
return LRUStorage::do_get_size(pSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t LRUStorageMT::get_items(uint64_t* pItems) const
|
cache_result_t LRUStorageMT::get_items(uint64_t* pItems) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return LRUStorage::do_get_items(pItems);
|
return LRUStorage::do_get_items(pItems);
|
||||||
}
|
}
|
||||||
|
|||||||
6
server/modules/filter/cache/lrustoragemt.hh
vendored
6
server/modules/filter/cache/lrustoragemt.hh
vendored
@ -13,7 +13,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <maxscale/ccdefs.hh>
|
#include <maxscale/ccdefs.hh>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "lrustorage.hh"
|
#include "lrustorage.hh"
|
||||||
|
|
||||||
class LRUStorageMT : public LRUStorage
|
class LRUStorageMT : public LRUStorage
|
||||||
@ -54,5 +56,5 @@ private:
|
|||||||
LRUStorageMT& operator=(const LRUStorageMT&);
|
LRUStorageMT& operator=(const LRUStorageMT&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable SPINLOCK m_lock;
|
mutable std::mutex m_lock;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -14,14 +14,12 @@
|
|||||||
#define MXS_MODULE_NAME "storage_inmemory"
|
#define MXS_MODULE_NAME "storage_inmemory"
|
||||||
#include "inmemorystoragemt.hh"
|
#include "inmemorystoragemt.hh"
|
||||||
|
|
||||||
using maxscale::SpinLockGuard;
|
|
||||||
using std::auto_ptr;
|
using std::auto_ptr;
|
||||||
|
|
||||||
InMemoryStorageMT::InMemoryStorageMT(const std::string& name,
|
InMemoryStorageMT::InMemoryStorageMT(const std::string& name,
|
||||||
const CACHE_STORAGE_CONFIG& config)
|
const CACHE_STORAGE_CONFIG& config)
|
||||||
: InMemoryStorage(name, config)
|
: InMemoryStorage(name, config)
|
||||||
{
|
{
|
||||||
spinlock_init(&m_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InMemoryStorageMT::~InMemoryStorageMT()
|
InMemoryStorageMT::~InMemoryStorageMT()
|
||||||
@ -38,7 +36,7 @@ auto_ptr<InMemoryStorageMT> InMemoryStorageMT::Create(const std::string& name,
|
|||||||
|
|
||||||
cache_result_t InMemoryStorageMT::get_info(uint32_t what, json_t** ppInfo) const
|
cache_result_t InMemoryStorageMT::get_info(uint32_t what, json_t** ppInfo) const
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return do_get_info(what, ppInfo);
|
return do_get_info(what, ppInfo);
|
||||||
}
|
}
|
||||||
@ -49,21 +47,21 @@ cache_result_t InMemoryStorageMT::get_value(const CACHE_KEY& key,
|
|||||||
uint32_t hard_ttl,
|
uint32_t hard_ttl,
|
||||||
GWBUF** ppResult)
|
GWBUF** ppResult)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return do_get_value(key, flags, soft_ttl, hard_ttl, ppResult);
|
return do_get_value(key, flags, soft_ttl, hard_ttl, ppResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t InMemoryStorageMT::put_value(const CACHE_KEY& key, const GWBUF& value)
|
cache_result_t InMemoryStorageMT::put_value(const CACHE_KEY& key, const GWBUF& value)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return do_put_value(key, value);
|
return do_put_value(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_result_t InMemoryStorageMT::del_value(const CACHE_KEY& key)
|
cache_result_t InMemoryStorageMT::del_value(const CACHE_KEY& key)
|
||||||
{
|
{
|
||||||
SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
return do_del_value(key);
|
return do_del_value(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <maxscale/ccdefs.hh>
|
#include <maxscale/ccdefs.hh>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "inmemorystorage.hh"
|
#include "inmemorystorage.hh"
|
||||||
|
|
||||||
class InMemoryStorageMT : public InMemoryStorage
|
class InMemoryStorageMT : public InMemoryStorage
|
||||||
@ -45,5 +47,5 @@ private:
|
|||||||
InMemoryStorageMT& operator=(const InMemoryStorageMT&);
|
InMemoryStorageMT& operator=(const InMemoryStorageMT&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable SPINLOCK m_lock;
|
mutable std::mutex m_lock;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -76,7 +76,6 @@
|
|||||||
#include <maxscale/protocol/mysql.h>
|
#include <maxscale/protocol/mysql.h>
|
||||||
#include <maxscale/pcre2.h>
|
#include <maxscale/pcre2.h>
|
||||||
#include <maxscale/alloc.h>
|
#include <maxscale/alloc.h>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
#include <maxscale/utils.h>
|
#include <maxscale/utils.h>
|
||||||
|
|
||||||
#include "rules.hh"
|
#include "rules.hh"
|
||||||
@ -1201,7 +1200,6 @@ int global_version = 1;
|
|||||||
Dbfw::Dbfw(MXS_CONFIG_PARAMETER* params)
|
Dbfw::Dbfw(MXS_CONFIG_PARAMETER* params)
|
||||||
: m_action((enum fw_actions)config_get_enum(params, "action", action_values))
|
: m_action((enum fw_actions)config_get_enum(params, "action", action_values))
|
||||||
, m_log_match(0)
|
, m_log_match(0)
|
||||||
, m_lock(SPINLOCK_INIT)
|
|
||||||
, m_filename(config_get_string(params, "rules"))
|
, m_filename(config_get_string(params, "rules"))
|
||||||
, m_version(atomic_add(&global_version, 1))
|
, m_version(atomic_add(&global_version, 1))
|
||||||
{
|
{
|
||||||
@ -1252,7 +1250,7 @@ int Dbfw::get_log_bitmask() const
|
|||||||
|
|
||||||
std::string Dbfw::get_rule_file() const
|
std::string Dbfw::get_rule_file() const
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
return m_filename;
|
return m_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,7 +1294,7 @@ bool Dbfw::do_reload_rules(std::string filename)
|
|||||||
|
|
||||||
bool Dbfw::reload_rules(std::string filename)
|
bool Dbfw::reload_rules(std::string filename)
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
return do_reload_rules(filename);
|
return do_reload_rules(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,15 +16,16 @@
|
|||||||
#include <maxscale/ccdefs.hh>
|
#include <maxscale/ccdefs.hh>
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <maxscale/filter.hh>
|
#include <maxscale/filter.hh>
|
||||||
#include <maxscale/query_classifier.h>
|
#include <maxscale/query_classifier.h>
|
||||||
#include <maxscale/spinlock.h>
|
|
||||||
|
|
||||||
#include "dbfwfilter.h"
|
#include "dbfwfilter.h"
|
||||||
|
|
||||||
@ -265,8 +266,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
fw_actions m_action; /*< Default operation mode, defaults to deny */
|
fw_actions m_action; /*< Default operation mode, defaults to deny */
|
||||||
int m_log_match;/*< Log matching and/or non-matching queries */
|
int m_log_match; /*< Log matching and/or non-matching queries */
|
||||||
SPINLOCK m_lock; /*< Instance spinlock */
|
mutable std::mutex m_lock; /*< Instance spinlock */
|
||||||
std::string m_filename; /*< Path to the rule file */
|
std::string m_filename; /*< Path to the rule file */
|
||||||
int m_version; /*< Latest rule file version, incremented on reload */
|
int m_version; /*< Latest rule file version, incremented on reload */
|
||||||
|
|
||||||
|
|||||||
@ -172,7 +172,6 @@ bool Shard::newer_than(const Shard& shard) const
|
|||||||
|
|
||||||
ShardManager::ShardManager()
|
ShardManager::ShardManager()
|
||||||
{
|
{
|
||||||
spinlock_init(&m_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShardManager::~ShardManager()
|
ShardManager::~ShardManager()
|
||||||
@ -181,7 +180,7 @@ ShardManager::~ShardManager()
|
|||||||
|
|
||||||
Shard ShardManager::get_shard(std::string user, double max_interval)
|
Shard ShardManager::get_shard(std::string user, double max_interval)
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
|
|
||||||
ShardMap::iterator iter = m_maps.find(user);
|
ShardMap::iterator iter = m_maps.find(user);
|
||||||
|
|
||||||
@ -203,7 +202,7 @@ Shard ShardManager::get_shard(std::string user, double max_interval)
|
|||||||
|
|
||||||
void ShardManager::update_shard(Shard& shard, std::string user)
|
void ShardManager::update_shard(Shard& shard, std::string user)
|
||||||
{
|
{
|
||||||
mxs::SpinLockGuard guard(m_lock);
|
std::lock_guard<std::mutex> guard(m_lock);
|
||||||
ShardMap::iterator iter = m_maps.find(user);
|
ShardMap::iterator iter = m_maps.find(user);
|
||||||
|
|
||||||
if (iter == m_maps.end() || shard.newer_than(iter->second))
|
if (iter == m_maps.end() || shard.newer_than(iter->second))
|
||||||
|
|||||||
@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
#include <maxscale/ccdefs.hh>
|
#include <maxscale/ccdefs.hh>
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <maxscale/service.h>
|
#include <maxscale/service.h>
|
||||||
#include <maxscale/spinlock.hh>
|
|
||||||
|
|
||||||
using namespace maxscale;
|
using namespace maxscale;
|
||||||
|
|
||||||
@ -142,6 +142,6 @@ public:
|
|||||||
void update_shard(Shard& shard, std::string user);
|
void update_shard(Shard& shard, std::string user);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SPINLOCK m_lock;
|
mutable std::mutex m_lock;
|
||||||
ShardMap m_maps;
|
ShardMap m_maps;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user