Remove template types from lock RAII wrapper usages (#1756)

C++17 has template type autodeduction. These wrappers include
std::lock_guard and std::unique_lock.
This commit is contained in:
Tyler Veness
2019-07-07 19:17:14 -07:00
committed by Peter Johnson
parent e582518bae
commit 841ef5d739
90 changed files with 621 additions and 621 deletions

View File

@@ -37,7 +37,7 @@ void ConfigurableSourceImpl::Start() {
bool ConfigurableSourceImpl::SetVideoMode(const VideoMode& mode,
CS_Status* status) {
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_mode = mode;
m_videoModes[0] = mode;
}
@@ -61,7 +61,7 @@ int ConfigurableSourceImpl::CreateProperty(const wpi::Twine& name,
CS_PropertyKind kind, int minimum,
int maximum, int step,
int defaultValue, int value) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
int ndx = CreateOrUpdateProperty(name,
[=] {
return std::make_unique<PropertyImpl>(
@@ -92,7 +92,7 @@ int ConfigurableSourceImpl::CreateProperty(
void ConfigurableSourceImpl::SetEnumPropertyChoices(
int property, wpi::ArrayRef<std::string> choices, CS_Status* status) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;

View File

@@ -36,7 +36,7 @@ Frame::Frame(SourceImpl& source, std::unique_ptr<Image> image, Time time)
Image* Frame::GetNearestImage(int width, int height) const {
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
Image* found = nullptr;
// Ideally we want the smallest image at least width/height in size
@@ -60,7 +60,7 @@ Image* Frame::GetNearestImage(int width, int height,
VideoMode::PixelFormat pixelFormat,
int jpegQuality) const {
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
Image* found = nullptr;
// We want the smallest image at least width/height (or the next largest),
@@ -253,7 +253,7 @@ Image* Frame::ConvertMJPEGToBGR(Image* image) {
// Save the result
Image* rv = newImage.release();
if (m_impl) {
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
m_impl->images.push_back(rv);
}
return rv;
@@ -274,7 +274,7 @@ Image* Frame::ConvertMJPEGToGray(Image* image) {
// Save the result
Image* rv = newImage.release();
if (m_impl) {
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
m_impl->images.push_back(rv);
}
return rv;
@@ -294,7 +294,7 @@ Image* Frame::ConvertYUYVToBGR(Image* image) {
// Save the result
Image* rv = newImage.release();
if (m_impl) {
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
m_impl->images.push_back(rv);
}
return rv;
@@ -314,7 +314,7 @@ Image* Frame::ConvertBGRToRGB565(Image* image) {
// Save the result
Image* rv = newImage.release();
if (m_impl) {
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
m_impl->images.push_back(rv);
}
return rv;
@@ -334,7 +334,7 @@ Image* Frame::ConvertRGB565ToBGR(Image* image) {
// Save the result
Image* rv = newImage.release();
if (m_impl) {
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
m_impl->images.push_back(rv);
}
return rv;
@@ -354,7 +354,7 @@ Image* Frame::ConvertBGRToGray(Image* image) {
// Save the result
Image* rv = newImage.release();
if (m_impl) {
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
m_impl->images.push_back(rv);
}
return rv;
@@ -374,7 +374,7 @@ Image* Frame::ConvertGrayToBGR(Image* image) {
// Save the result
Image* rv = newImage.release();
if (m_impl) {
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
m_impl->images.push_back(rv);
}
return rv;
@@ -383,7 +383,7 @@ Image* Frame::ConvertGrayToBGR(Image* image) {
Image* Frame::ConvertBGRToMJPEG(Image* image, int quality) {
if (!image || image->pixelFormat != VideoMode::kBGR) return nullptr;
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
// Allocate a JPEG image. We don't actually know what the resulting size
// will be; while the destination will automatically grow, doing so will
@@ -414,7 +414,7 @@ Image* Frame::ConvertBGRToMJPEG(Image* image, int quality) {
Image* Frame::ConvertGrayToMJPEG(Image* image, int quality) {
if (!image || image->pixelFormat != VideoMode::kGray) return nullptr;
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
// Allocate a JPEG image. We don't actually know what the resulting size
// will be; while the destination will automatically grow, doing so will
@@ -446,7 +446,7 @@ Image* Frame::GetImageImpl(int width, int height,
VideoMode::PixelFormat pixelFormat,
int requiredJpegQuality, int defaultJpegQuality) {
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
Image* cur = GetNearestImage(width, height, pixelFormat, requiredJpegQuality);
if (!cur || cur->Is(width, height, pixelFormat, requiredJpegQuality))
return cur;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -80,42 +80,42 @@ class Frame {
int GetOriginalWidth() const {
if (!m_impl) return 0;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
if (m_impl->images.empty()) return 0;
return m_impl->images[0]->width;
}
int GetOriginalHeight() const {
if (!m_impl) return 0;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
if (m_impl->images.empty()) return 0;
return m_impl->images[0]->height;
}
int GetOriginalPixelFormat() const {
if (!m_impl) return 0;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
if (m_impl->images.empty()) return 0;
return m_impl->images[0]->pixelFormat;
}
int GetOriginalJpegQuality() const {
if (!m_impl) return 0;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
if (m_impl->images.empty()) return 0;
return m_impl->images[0]->jpegQuality;
}
Image* GetExistingImage(size_t i = 0) const {
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
if (i >= m_impl->images.size()) return nullptr;
return m_impl->images[i];
}
Image* GetExistingImage(int width, int height) const {
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
for (auto i : m_impl->images) {
if (i->Is(width, height)) return i;
}
@@ -125,7 +125,7 @@ class Frame {
Image* GetExistingImage(int width, int height,
VideoMode::PixelFormat pixelFormat) const {
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
for (auto i : m_impl->images) {
if (i->Is(width, height, pixelFormat)) return i;
}
@@ -136,7 +136,7 @@ class Frame {
VideoMode::PixelFormat pixelFormat,
int jpegQuality) const {
if (!m_impl) return nullptr;
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
std::lock_guard lock(m_impl->mutex);
for (auto i : m_impl->images) {
if (i->Is(width, height, pixelFormat, jpegQuality)) return i;
}

View File

@@ -37,7 +37,7 @@ HttpCameraImpl::~HttpCameraImpl() {
// Close file if it's open
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_streamConn) m_streamConn->stream->close();
if (m_settingsConn) m_settingsConn->stream->close();
}
@@ -64,7 +64,7 @@ void HttpCameraImpl::Start() {
void HttpCameraImpl::MonitorThreadMain() {
while (m_active) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
// sleep for 1 second between checks
m_monitorCond.wait_for(lock, std::chrono::seconds(1),
[=] { return !m_active; });
@@ -95,7 +95,7 @@ void HttpCameraImpl::StreamThreadMain() {
// disconnect if not enabled
if (!IsEnabled()) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (m_streamConn) m_streamConn->stream->close();
// Wait for enable
m_sinkEnabledCond.wait(lock, [=] { return !m_active || IsEnabled(); });
@@ -117,7 +117,7 @@ void HttpCameraImpl::StreamThreadMain() {
// stream
DeviceStream(conn->is, boundary);
{
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
m_streamConn = nullptr;
}
}
@@ -131,7 +131,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
// Build the request
wpi::HttpRequest req;
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_locations.empty()) {
SERROR("locations array is empty!?");
std::this_thread::sleep_for(std::chrono::seconds(1));
@@ -153,7 +153,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
// update m_streamConn
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_frameCount = 1; // avoid a race with monitor thread
m_streamConn = std::move(connPtr);
}
@@ -161,7 +161,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
std::string warn;
if (!conn->Handshake(req, &warn)) {
SWARNING(GetName() << ": " << warn);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_streamConn = nullptr;
return nullptr;
}
@@ -173,7 +173,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
if (mediaType != "multipart/x-mixed-replace") {
SWARNING("\"" << req.host << "\": unrecognized Content-Type \"" << mediaType
<< "\"");
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_streamConn = nullptr;
return nullptr;
}
@@ -198,7 +198,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
if (boundary.empty()) {
SWARNING("\"" << req.host
<< "\": empty multi-part boundary or no Content-Type");
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_streamConn = nullptr;
return nullptr;
}
@@ -298,7 +298,7 @@ void HttpCameraImpl::SettingsThreadMain() {
for (;;) {
wpi::HttpRequest req;
{
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
m_settingsCond.wait(lock, [=] {
return !m_active || (m_prefLocation != -1 && !m_settings.empty());
});
@@ -326,7 +326,7 @@ void HttpCameraImpl::DeviceSendSettings(wpi::HttpRequest& req) {
// update m_settingsConn
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_settingsConn = std::move(connPtr);
}
@@ -338,7 +338,7 @@ void HttpCameraImpl::DeviceSendSettings(wpi::HttpRequest& req) {
}
CS_HttpCameraKind HttpCameraImpl::GetKind() const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
return m_kind;
}
@@ -356,7 +356,7 @@ bool HttpCameraImpl::SetUrls(wpi::ArrayRef<std::string> urls,
}
}
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_locations.swap(locations);
m_nextLocation = 0;
m_streamSettingsUpdated = true;
@@ -364,7 +364,7 @@ bool HttpCameraImpl::SetUrls(wpi::ArrayRef<std::string> urls,
}
std::vector<std::string> HttpCameraImpl::GetUrls() const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
std::vector<std::string> urls;
for (const auto& loc : m_locations) urls.push_back(loc.url);
return urls;
@@ -375,7 +375,7 @@ void HttpCameraImpl::CreateProperty(const wpi::Twine& name,
bool viaSettings, CS_PropertyKind kind,
int minimum, int maximum, int step,
int defaultValue, int value) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_propertyData.emplace_back(std::make_unique<PropertyData>(
name, httpParam, viaSettings, kind, minimum, maximum, step, defaultValue,
value));
@@ -389,7 +389,7 @@ template <typename T>
void HttpCameraImpl::CreateEnumProperty(
const wpi::Twine& name, const wpi::Twine& httpParam, bool viaSettings,
int defaultValue, int value, std::initializer_list<T> choices) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_propertyData.emplace_back(std::make_unique<PropertyData>(
name, httpParam, viaSettings, CS_PROP_ENUM, 0, choices.size() - 1, 1,
defaultValue, value));
@@ -412,7 +412,7 @@ std::unique_ptr<PropertyImpl> HttpCameraImpl::CreateEmptyProperty(
}
bool HttpCameraImpl::CacheProperties(CS_Status* status) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
// Pretty typical set of video modes
m_videoModes.clear();
@@ -468,7 +468,7 @@ void HttpCameraImpl::SetExposureManual(int value, CS_Status* status) {
bool HttpCameraImpl::SetVideoMode(const VideoMode& mode, CS_Status* status) {
if (mode.pixelFormat != VideoMode::kMJPEG) return false;
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_mode = mode;
m_streamSettingsUpdated = true;
return true;
@@ -497,7 +497,7 @@ bool AxisCameraImpl::CacheProperties(CS_Status* status) const {
true, CS_PROP_INTEGER, 0, 100, 1, 50, 50);
// TODO: get video modes from device
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_videoModes.clear();
m_videoModes.emplace_back(VideoMode::kMJPEG, 640, 480, 30);
m_videoModes.emplace_back(VideoMode::kMJPEG, 480, 360, 30);

View File

@@ -105,18 +105,18 @@ class MjpegServerImpl::ConnThread : public wpi::SafeThread {
wpi::StringRef GetName() { return m_name; }
std::shared_ptr<SourceImpl> GetSource() {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
return m_source;
}
void StartStream() {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_source) m_source->EnableSink();
m_streaming = true;
}
void StopStream() {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_source) m_source->DisableSink();
m_streaming = false;
}
@@ -865,7 +865,7 @@ void MjpegServerImpl::ConnThread::ProcessRequest() {
// worker thread for clients that connected to this server
void MjpegServerImpl::ConnThread::Main() {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
while (m_active) {
while (!m_stream) {
m_cond.wait(lock);
@@ -898,7 +898,7 @@ void MjpegServerImpl::ServerThreadMain() {
auto source = GetSource();
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
// Find unoccupied worker thread, or create one if necessary
auto it = std::find_if(m_connThreads.begin(), m_connThreads.end(),
[](const wpi::SafeThreadOwner<ConnThread>& owner) {
@@ -937,7 +937,7 @@ void MjpegServerImpl::ServerThreadMain() {
}
void MjpegServerImpl::SetSourceImpl(std::shared_ptr<SourceImpl> source) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
for (auto& connThread : m_connThreads) {
if (auto thr = connThread.GetThread()) {
if (thr->m_source != source) {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -102,7 +102,7 @@ void Notifier::Stop() { m_owner.Stop(); }
void Notifier::Thread::Main() {
if (m_on_start) m_on_start();
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
while (m_active) {
while (m_notifications.empty()) {
m_cond.wait(lock);

View File

@@ -18,7 +18,7 @@ int PropertyContainer::GetPropertyIndex(const wpi::Twine& name) const {
// We can't fail, so instead we create a new index if caching fails.
CS_Status status = 0;
if (!m_properties_cached) CacheProperties(&status);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
wpi::SmallVector<char, 64> nameBuf;
int& ndx = m_properties[name.toStringRef(nameBuf)];
if (ndx == 0) {
@@ -33,7 +33,7 @@ wpi::ArrayRef<int> PropertyContainer::EnumerateProperties(
wpi::SmallVectorImpl<int>& vec, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status))
return wpi::ArrayRef<int>{};
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
for (int i = 0; i < static_cast<int>(m_propertyData.size()); ++i) {
if (m_propertyData[i]) vec.push_back(i + 1);
}
@@ -43,7 +43,7 @@ wpi::ArrayRef<int> PropertyContainer::EnumerateProperties(
CS_PropertyKind PropertyContainer::GetPropertyKind(int property) const {
CS_Status status = 0;
if (!m_properties_cached && !CacheProperties(&status)) return CS_PROP_NONE;
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) return CS_PROP_NONE;
return prop->propKind;
@@ -52,7 +52,7 @@ CS_PropertyKind PropertyContainer::GetPropertyKind(int property) const {
wpi::StringRef PropertyContainer::GetPropertyName(
int property, wpi::SmallVectorImpl<char>& buf, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return wpi::StringRef{};
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -64,7 +64,7 @@ wpi::StringRef PropertyContainer::GetPropertyName(
int PropertyContainer::GetProperty(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -80,7 +80,7 @@ int PropertyContainer::GetProperty(int property, CS_Status* status) const {
void PropertyContainer::SetProperty(int property, int value,
CS_Status* status) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -101,7 +101,7 @@ void PropertyContainer::SetProperty(int property, int value,
int PropertyContainer::GetPropertyMin(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -112,7 +112,7 @@ int PropertyContainer::GetPropertyMin(int property, CS_Status* status) const {
int PropertyContainer::GetPropertyMax(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -123,7 +123,7 @@ int PropertyContainer::GetPropertyMax(int property, CS_Status* status) const {
int PropertyContainer::GetPropertyStep(int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -135,7 +135,7 @@ int PropertyContainer::GetPropertyStep(int property, CS_Status* status) const {
int PropertyContainer::GetPropertyDefault(int property,
CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return 0;
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -147,7 +147,7 @@ int PropertyContainer::GetPropertyDefault(int property,
wpi::StringRef PropertyContainer::GetStringProperty(
int property, wpi::SmallVectorImpl<char>& buf, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return wpi::StringRef{};
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -164,7 +164,7 @@ wpi::StringRef PropertyContainer::GetStringProperty(
void PropertyContainer::SetStringProperty(int property, const wpi::Twine& value,
CS_Status* status) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;
@@ -186,7 +186,7 @@ std::vector<std::string> PropertyContainer::GetEnumPropertyChoices(
int property, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status))
return std::vector<std::string>{};
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
*status = CS_INVALID_PROPERTY;

View File

@@ -30,18 +30,18 @@ SinkImpl::~SinkImpl() {
}
void SinkImpl::SetDescription(const wpi::Twine& description) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_description = description.str();
}
wpi::StringRef SinkImpl::GetDescription(wpi::SmallVectorImpl<char>& buf) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
buf.append(m_description.begin(), m_description.end());
return wpi::StringRef{buf.data(), buf.size()};
}
void SinkImpl::Enable() {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
++m_enabledCount;
if (m_enabledCount == 1) {
if (m_source) m_source->EnableSink();
@@ -50,7 +50,7 @@ void SinkImpl::Enable() {
}
void SinkImpl::Disable() {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
--m_enabledCount;
if (m_enabledCount == 0) {
if (m_source) m_source->DisableSink();
@@ -59,7 +59,7 @@ void SinkImpl::Disable() {
}
void SinkImpl::SetEnabled(bool enabled) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (enabled && m_enabledCount == 0) {
if (m_source) m_source->EnableSink();
m_enabledCount = 1;
@@ -73,7 +73,7 @@ void SinkImpl::SetEnabled(bool enabled) {
void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (m_source == source) return;
if (m_source) {
if (m_enabledCount > 0) m_source->DisableSink();
@@ -89,13 +89,13 @@ void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
}
std::string SinkImpl::GetError() const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (!m_source) return "no source connected";
return m_source->GetCurFrame().GetError();
}
wpi::StringRef SinkImpl::GetError(wpi::SmallVectorImpl<char>& buf) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (!m_source) return "no source connected";
// Make a copy as it's shared data
wpi::StringRef error = m_source->GetCurFrame().GetError();

View File

@@ -48,7 +48,7 @@ class SinkImpl : public PropertyContainer {
void SetSource(std::shared_ptr<SourceImpl> source);
std::shared_ptr<SourceImpl> GetSource() const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
return m_source;
}

View File

@@ -44,13 +44,13 @@ SourceImpl::~SourceImpl() {
}
void SourceImpl::SetDescription(const wpi::Twine& description) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_description = description.str();
}
wpi::StringRef SourceImpl::GetDescription(
wpi::SmallVectorImpl<char>& buf) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
buf.append(m_description.begin(), m_description.end());
return wpi::StringRef{buf.data(), buf.size()};
}
@@ -64,24 +64,24 @@ void SourceImpl::SetConnected(bool connected) {
}
uint64_t SourceImpl::GetCurFrameTime() {
std::unique_lock<wpi::mutex> lock{m_frameMutex};
std::unique_lock lock{m_frameMutex};
return m_frame.GetTime();
}
Frame SourceImpl::GetCurFrame() {
std::unique_lock<wpi::mutex> lock{m_frameMutex};
std::unique_lock lock{m_frameMutex};
return m_frame;
}
Frame SourceImpl::GetNextFrame() {
std::unique_lock<wpi::mutex> lock{m_frameMutex};
std::unique_lock lock{m_frameMutex};
auto oldTime = m_frame.GetTime();
m_frameCv.wait(lock, [=] { return m_frame.GetTime() != oldTime; });
return m_frame;
}
Frame SourceImpl::GetNextFrame(double timeout) {
std::unique_lock<wpi::mutex> lock{m_frameMutex};
std::unique_lock lock{m_frameMutex};
auto oldTime = m_frame.GetTime();
if (!m_frameCv.wait_for(
lock, std::chrono::milliseconds(static_cast<int>(timeout * 1000)),
@@ -93,7 +93,7 @@ Frame SourceImpl::GetNextFrame(double timeout) {
void SourceImpl::Wakeup() {
{
std::lock_guard<wpi::mutex> lock{m_frameMutex};
std::lock_guard lock{m_frameMutex};
m_frame = Frame{*this, wpi::StringRef{}, 0};
}
m_frameCv.notify_all();
@@ -134,7 +134,7 @@ void SourceImpl::SetExposureManual(int value, CS_Status* status) {
VideoMode SourceImpl::GetVideoMode(CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) return VideoMode{};
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
return m_mode;
}
@@ -380,7 +380,7 @@ std::vector<VideoMode> SourceImpl::EnumerateVideoModes(
CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status))
return std::vector<VideoMode>{};
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
return m_videoModes;
}
@@ -388,7 +388,7 @@ std::unique_ptr<Image> SourceImpl::AllocImage(
VideoMode::PixelFormat pixelFormat, int width, int height, size_t size) {
std::unique_ptr<Image> image;
{
std::lock_guard<wpi::mutex> lock{m_poolMutex};
std::lock_guard lock{m_poolMutex};
// find the smallest existing frame that is at least big enough.
int found = -1;
for (size_t i = 0; i < m_imagesAvail.size(); ++i) {
@@ -440,7 +440,7 @@ void SourceImpl::PutFrame(std::unique_ptr<Image> image, Frame::Time time) {
// Update frame
{
std::lock_guard<wpi::mutex> lock{m_frameMutex};
std::lock_guard lock{m_frameMutex};
m_frame = Frame{*this, std::move(image), time};
}
@@ -451,7 +451,7 @@ void SourceImpl::PutFrame(std::unique_ptr<Image> image, Frame::Time time) {
void SourceImpl::PutError(const wpi::Twine& msg, Frame::Time time) {
// Update frame
{
std::lock_guard<wpi::mutex> lock{m_frameMutex};
std::lock_guard lock{m_frameMutex};
m_frame = Frame{*this, msg, time};
}
@@ -489,7 +489,7 @@ void SourceImpl::UpdatePropertyValue(int property, bool setString, int value,
}
void SourceImpl::ReleaseImage(std::unique_ptr<Image> image) {
std::lock_guard<wpi::mutex> lock{m_poolMutex};
std::lock_guard lock{m_poolMutex};
if (m_destroyFrames) return;
// Return the frame to the pool. First try to find an empty slot, otherwise
// add it to the end.
@@ -511,7 +511,7 @@ void SourceImpl::ReleaseImage(std::unique_ptr<Image> image) {
}
std::unique_ptr<Frame::Impl> SourceImpl::AllocFrameImpl() {
std::lock_guard<wpi::mutex> lock{m_poolMutex};
std::lock_guard lock{m_poolMutex};
if (m_framesAvail.empty()) return std::make_unique<Frame::Impl>(*this);
@@ -521,7 +521,7 @@ std::unique_ptr<Frame::Impl> SourceImpl::AllocFrameImpl() {
}
void SourceImpl::ReleaseFrameImpl(std::unique_ptr<Frame::Impl> impl) {
std::lock_guard<wpi::mutex> lock{m_poolMutex};
std::lock_guard lock{m_poolMutex};
if (m_destroyFrames) return;
m_framesAvail.push_back(std::move(impl));
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -53,7 +53,7 @@ void Telemetry::Start() { m_owner.Start(m_notifier); }
void Telemetry::Stop() { m_owner.Stop(); }
void Telemetry::Thread::Main() {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
auto prevTime = std::chrono::steady_clock::now();
while (m_active) {
double period = m_period;

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -78,7 +78,7 @@ template <typename THandle, typename TStruct, int typeValue, typename TMutex>
template <typename... Args>
THandle UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Allocate(
Args&&... args) {
std::lock_guard<TMutex> sync(m_handleMutex);
std::lock_guard sync(m_handleMutex);
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] == nullptr) {
@@ -96,7 +96,7 @@ THandle UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Allocate(
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
THandle UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Allocate(
std::shared_ptr<THandle> structure) {
std::lock_guard<TMutex> sync(m_handleMutex);
std::lock_guard sync(m_handleMutex);
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] == nullptr) {
@@ -117,7 +117,7 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Get(
auto index =
handle.GetTypedIndex(static_cast<typename THandle::Type>(typeValue));
if (index < 0) return nullptr;
std::lock_guard<TMutex> sync(m_handleMutex);
std::lock_guard sync(m_handleMutex);
if (index >= static_cast<int>(m_structures.size())) return nullptr;
return m_structures[index];
}
@@ -129,7 +129,7 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Free(
auto index =
handle.GetTypedIndex(static_cast<typename THandle::Type>(typeValue));
if (index < 0) return nullptr;
std::lock_guard<TMutex> sync(m_handleMutex);
std::lock_guard sync(m_handleMutex);
if (index >= static_cast<int>(m_structures.size())) return nullptr;
auto rv = std::move(m_structures[index]);
m_structures[index].reset();
@@ -148,7 +148,7 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::GetAll(
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
inline std::vector<std::shared_ptr<TStruct>>
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::FreeAll() {
std::lock_guard<TMutex> sync(m_handleMutex);
std::lock_guard sync(m_handleMutex);
auto rv = std::move(m_structures);
m_structures.clear();
return rv;
@@ -158,7 +158,7 @@ template <typename THandle, typename TStruct, int typeValue, typename TMutex>
template <typename F>
inline void
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::ForEach(F func) {
std::lock_guard<TMutex> sync(m_handleMutex);
std::lock_guard sync(m_handleMutex);
for (size_t i = 0; i < m_structures.size(); i++) {
if (m_structures[i] != nullptr) func(MakeHandle(i), *(m_structures[i]));
}
@@ -168,7 +168,7 @@ template <typename THandle, typename TStruct, int typeValue, typename TMutex>
template <typename F>
inline std::pair<THandle, std::shared_ptr<TStruct>>
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::FindIf(F func) {
std::lock_guard<TMutex> sync(m_handleMutex);
std::lock_guard sync(m_handleMutex);
for (size_t i = 0; i < m_structures.size(); i++) {
auto& structure = m_structures[i];
if (structure != nullptr && func(*structure))