mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
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:
committed by
Peter Johnson
parent
e582518bae
commit
841ef5d739
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user