utilities: Swapped to use std C++11 mutex/threading constructs

This commit is contained in:
Justin Berger
2017-12-01 12:09:51 -07:00
parent a4faf86387
commit 3519c8f247
3 changed files with 9 additions and 48 deletions

View File

@@ -18,6 +18,7 @@
#include <cstdint>
#include <iostream>
#include <memory>
#include <mutex>
#include <utility>
void on_signal(uv_signal_t* signal, int signum)
@@ -490,7 +491,7 @@ void cmServerBase::StartShutDown()
SIGHUPHandler.reset();
{
cm::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
for (auto& connection : Connections) {
connection->OnConnectionShuttingDown();
}
@@ -537,7 +538,7 @@ cmServerBase::~cmServerBase()
void cmServerBase::AddNewConnection(cmConnection* ownedConnection)
{
{
cm::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
Connections.emplace_back(ownedConnection);
}
ownedConnection->SetServer(this);
@@ -554,7 +555,7 @@ void cmServerBase::OnDisconnect(cmConnection* pConnection)
return m.get() == pConnection;
};
{
cm::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
Connections.erase(
std::remove_if(Connections.begin(), Connections.end(), pred),
Connections.end());

View File

@@ -4,9 +4,9 @@
#include "cmUVHandlePtr.h"
#include <assert.h>
#include <mutex>
#include <stdlib.h>
#include "cm_thread.hxx"
#include "cm_uv.h"
namespace cm {
@@ -97,16 +97,16 @@ struct uv_handle_deleter<uv_async_t>
* which is mandated by the standard for Deleter on
* shared_ptrs.
*/
std::shared_ptr<cm::mutex> handleMutex;
std::shared_ptr<std::mutex> handleMutex;
uv_handle_deleter()
: handleMutex(std::make_shared<cm::mutex>())
: handleMutex(std::make_shared<std::mutex>())
{
}
void operator()(uv_async_t* handle)
{
cm::lock_guard<cm::mutex> lock(*handleMutex);
std::lock_guard<std::mutex> lock(*handleMutex);
default_delete(handle);
}
};
@@ -116,7 +116,7 @@ void uv_async_ptr::send()
auto deleter = std::get_deleter<uv_handle_deleter<uv_async_t>>(this->handle);
assert(deleter);
cm::lock_guard<cm::mutex> lock(*deleter->handleMutex);
std::lock_guard<std::mutex> lock(*deleter->handleMutex);
if (this->handle) {
uv_async_send(*this);
}

View File

@@ -7,34 +7,6 @@
#include "cm_uv.h"
namespace cm {
class mutex
{
CM_DISABLE_COPY(mutex)
uv_mutex_t _M_;
public:
mutex() { uv_mutex_init(&_M_); }
~mutex() { uv_mutex_destroy(&_M_); }
void lock() { uv_mutex_lock(&_M_); }
void unlock() { uv_mutex_unlock(&_M_); }
};
template <typename T>
class lock_guard
{
T& _mutex;
CM_DISABLE_COPY(lock_guard)
public:
lock_guard(T& m)
: _mutex(m)
{
_mutex.lock();
}
~lock_guard() { _mutex.unlock(); }
};
class shared_mutex
{
@@ -68,17 +40,5 @@ public:
}
~shared_lock() { _mutex.unlock_shared(); }
};
template <typename T>
class unique_lock : public lock_guard<T>
{
CM_DISABLE_COPY(unique_lock)
public:
unique_lock(T& m)
: lock_guard<T>(m)
{
}
};
}
#endif