mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-25 16:09:42 -06:00
utilities: Swapped to use std C++11 mutex/threading constructs
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user