Use wpi::mutex instead of std::mutex. (#730)

This uses a priority-aware mutex on Linux platforms.

Fixes #729.
This commit is contained in:
Peter Johnson
2017-11-13 09:51:48 -08:00
committed by GitHub
parent 35d68d2a34
commit 4d559f3856
86 changed files with 491 additions and 839 deletions

View File

@@ -8,19 +8,19 @@
#include "HAL/handles/HandlesInternal.h"
#include <algorithm>
#include <mutex>
#include <llvm/SmallVector.h>
#include <support/mutex.h>
namespace hal {
static llvm::SmallVector<HandleBase*, 32> globalHandles;
static std::mutex& GetGlobalHandleMutex() {
static std::mutex globalHandleMutex;
static wpi::mutex& GetGlobalHandleMutex() {
static wpi::mutex globalHandleMutex;
return globalHandleMutex;
}
HandleBase::HandleBase() {
std::lock_guard<std::mutex> lock(GetGlobalHandleMutex());
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
if (index == globalHandles.end()) {
globalHandles.push_back(this);
@@ -30,7 +30,7 @@ HandleBase::HandleBase() {
}
HandleBase::~HandleBase() {
std::lock_guard<std::mutex> lock(GetGlobalHandleMutex());
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
if (index != globalHandles.end()) {
*index = nullptr;
@@ -45,7 +45,7 @@ void HandleBase::ResetHandles() {
}
void HandleBase::ResetGlobalHandles() {
std::unique_lock<std::mutex> lock(GetGlobalHandleMutex());
std::unique_lock<wpi::mutex> lock(GetGlobalHandleMutex());
for (auto&& i : globalHandles) {
if (i != nullptr) {
lock.unlock();