mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
artf4156: Replaced synchronization primitives with C++11 equivalents
Change-Id: I90da739347e875efda2a29dd5484b6dda3cd4753
This commit is contained in:
committed by
James Kuszmaul
parent
7f5ee01d3e
commit
3f59f3472a
@@ -7,8 +7,9 @@
|
||||
#include "HAL/cpp/Resource.hpp"
|
||||
#include "HAL/Errors.hpp"
|
||||
#include <cstddef>
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
ReentrantSemaphore Resource::m_createLock;
|
||||
priority_recursive_mutex Resource::m_createLock;
|
||||
|
||||
/**
|
||||
* Allocate storage for a new instance of Resource.
|
||||
@@ -17,7 +18,7 @@ ReentrantSemaphore Resource::m_createLock;
|
||||
*/
|
||||
Resource::Resource(uint32_t elements)
|
||||
{
|
||||
Synchronized sync(m_createLock);
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_createLock);
|
||||
m_size = elements;
|
||||
m_isAllocated = new bool[m_size];
|
||||
for (uint32_t i=0; i < m_size; i++)
|
||||
@@ -38,7 +39,7 @@ Resource::Resource(uint32_t elements)
|
||||
*/
|
||||
/*static*/ void Resource::CreateResourceObject(Resource **r, uint32_t elements)
|
||||
{
|
||||
Synchronized sync(m_createLock);
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_createLock);
|
||||
if (*r == NULL)
|
||||
{
|
||||
*r = new Resource(elements);
|
||||
@@ -61,7 +62,7 @@ Resource::~Resource()
|
||||
*/
|
||||
uint32_t Resource::Allocate(const char *resourceDesc)
|
||||
{
|
||||
Synchronized sync(m_allocateLock);
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
for (uint32_t i=0; i < m_size; i++)
|
||||
{
|
||||
if (!m_isAllocated[i])
|
||||
@@ -81,7 +82,7 @@ uint32_t Resource::Allocate(const char *resourceDesc)
|
||||
*/
|
||||
uint32_t Resource::Allocate(uint32_t index, const char *resourceDesc)
|
||||
{
|
||||
Synchronized sync(m_allocateLock);
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index >= m_size)
|
||||
{
|
||||
// TODO: wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
@@ -104,7 +105,7 @@ uint32_t Resource::Allocate(uint32_t index, const char *resourceDesc)
|
||||
*/
|
||||
void Resource::Free(uint32_t index)
|
||||
{
|
||||
Synchronized sync(m_allocateLock);
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index == ~0ul) return;
|
||||
if (index >= m_size)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user