mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Use wpi::mutex instead of std::mutex. (#105)
This uses a priority-aware mutex on Linux platforms.
This commit is contained in:
@@ -9,9 +9,7 @@
|
||||
#define CSCORE_CVSINKIMPL_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ bool CvSourceImpl::CacheProperties(CS_Status* status) const {
|
||||
}
|
||||
|
||||
void CvSourceImpl::SetProperty(int property, int value, CS_Status* status) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = static_cast<PropertyData*>(GetProperty(property));
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -64,7 +64,7 @@ void CvSourceImpl::SetProperty(int property, int value, CS_Status* status) {
|
||||
|
||||
void CvSourceImpl::SetStringProperty(int property, llvm::StringRef value,
|
||||
CS_Status* status) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = static_cast<PropertyData*>(GetProperty(property));
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -170,7 +170,7 @@ void CvSourceImpl::NotifyError(llvm::StringRef msg) {
|
||||
int CvSourceImpl::CreateProperty(llvm::StringRef name, CS_PropertyKind kind,
|
||||
int minimum, int maximum, int step,
|
||||
int defaultValue, int value) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
int& ndx = m_properties[name];
|
||||
if (ndx == 0) {
|
||||
// create a new index
|
||||
@@ -204,7 +204,7 @@ int CvSourceImpl::CreateProperty(
|
||||
void CvSourceImpl::SetEnumPropertyChoices(int property,
|
||||
llvm::ArrayRef<std::string> choices,
|
||||
CS_Status* status) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
|
||||
@@ -33,7 +33,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<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
Image* found = nullptr;
|
||||
|
||||
// Ideally we want the smallest image at least width/height in size
|
||||
@@ -56,7 +56,7 @@ Image* Frame::GetNearestImage(int width, int height) const {
|
||||
Image* Frame::GetNearestImage(int width, int height,
|
||||
VideoMode::PixelFormat pixelFormat) const {
|
||||
if (!m_impl) return nullptr;
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
Image* found = nullptr;
|
||||
|
||||
// We want the smallest image at least width/height (or the next largest),
|
||||
@@ -238,7 +238,7 @@ Image* Frame::ConvertMJPEGToBGR(Image* image) {
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -259,7 +259,7 @@ Image* Frame::ConvertMJPEGToGray(Image* image) {
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -279,7 +279,7 @@ Image* Frame::ConvertYUYVToBGR(Image* image) {
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -299,7 +299,7 @@ Image* Frame::ConvertBGRToRGB565(Image* image) {
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -319,7 +319,7 @@ Image* Frame::ConvertRGB565ToBGR(Image* image) {
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -339,7 +339,7 @@ Image* Frame::ConvertBGRToGray(Image* image) {
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -359,7 +359,7 @@ Image* Frame::ConvertGrayToBGR(Image* image) {
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
@@ -368,7 +368,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<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> 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
|
||||
@@ -399,7 +399,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<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> 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
|
||||
@@ -430,7 +430,7 @@ Image* Frame::ConvertGrayToMJPEG(Image* image, int quality) {
|
||||
Image* Frame::GetImage(int width, int height,
|
||||
VideoMode::PixelFormat pixelFormat, int jpegQuality) {
|
||||
if (!m_impl) return nullptr;
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
Image* cur = GetNearestImage(width, height, pixelFormat);
|
||||
if (!cur || cur->Is(width, height, pixelFormat)) return cur;
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/SmallVector.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Image.h"
|
||||
#include "cscore_cpp.h"
|
||||
@@ -34,7 +34,7 @@ class Frame {
|
||||
struct Impl {
|
||||
explicit Impl(SourceImpl& source_) : source(source_) {}
|
||||
|
||||
std::recursive_mutex mutex;
|
||||
wpi::recursive_mutex mutex;
|
||||
std::atomic_int refcount{0};
|
||||
Time time{0};
|
||||
SourceImpl& source;
|
||||
@@ -79,35 +79,35 @@ class Frame {
|
||||
|
||||
int GetOriginalWidth() const {
|
||||
if (!m_impl) return 0;
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> 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<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> 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<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
if (m_impl->images.empty()) return 0;
|
||||
return m_impl->images[0]->pixelFormat;
|
||||
}
|
||||
|
||||
Image* GetExistingImage(size_t i = 0) const {
|
||||
if (!m_impl) return nullptr;
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> 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<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
for (auto i : m_impl->images) {
|
||||
if (i->Is(width, height)) return i;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ class Frame {
|
||||
Image* GetExistingImage(int width, int height,
|
||||
VideoMode::PixelFormat pixelFormat) const {
|
||||
if (!m_impl) return nullptr;
|
||||
std::lock_guard<std::recursive_mutex> lock(m_impl->mutex);
|
||||
std::lock_guard<wpi::recursive_mutex> lock(m_impl->mutex);
|
||||
for (auto i : m_impl->images) {
|
||||
if (i->Is(width, height, pixelFormat)) return i;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ HttpCameraImpl::~HttpCameraImpl() {
|
||||
|
||||
// Close file if it's open
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_streamConn) m_streamConn->stream->close();
|
||||
if (m_settingsConn) m_settingsConn->stream->close();
|
||||
}
|
||||
@@ -69,7 +69,7 @@ void HttpCameraImpl::StreamThreadMain() {
|
||||
|
||||
// disconnect if no one is listening
|
||||
if (m_numSinksEnabled == 0) {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
if (m_streamConn) m_streamConn->stream->close();
|
||||
// Wait for a sink to enable
|
||||
m_sinkEnabledCond.wait(
|
||||
@@ -102,7 +102,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
|
||||
// Build the request
|
||||
wpi::HttpRequest req;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_locations.empty()) {
|
||||
SERROR("locations array is empty!?");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
@@ -124,14 +124,14 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
|
||||
|
||||
// update m_streamConn
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_streamConn = std::move(connPtr);
|
||||
}
|
||||
|
||||
std::string warn;
|
||||
if (!conn->Handshake(req, &warn)) {
|
||||
SWARNING(GetName() << ": " << warn);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_streamConn = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
|
||||
if (mediaType != "multipart/x-mixed-replace") {
|
||||
SWARNING("\"" << req.host << "\": unrecognized Content-Type \"" << mediaType
|
||||
<< "\"");
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_streamConn = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ wpi::HttpConnection* HttpCameraImpl::DeviceStreamConnect(
|
||||
if (boundary.empty()) {
|
||||
SWARNING("\"" << req.host
|
||||
<< "\": empty multi-part boundary or no Content-Type");
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_streamConn = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -258,7 +258,7 @@ void HttpCameraImpl::SettingsThreadMain() {
|
||||
for (;;) {
|
||||
wpi::HttpRequest req;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
m_settingsCond.wait(lock, [=] {
|
||||
return !m_active || (m_prefLocation != -1 && !m_settings.empty());
|
||||
});
|
||||
@@ -286,7 +286,7 @@ void HttpCameraImpl::DeviceSendSettings(wpi::HttpRequest& req) {
|
||||
|
||||
// update m_settingsConn
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_settingsConn = std::move(connPtr);
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ void HttpCameraImpl::DeviceSendSettings(wpi::HttpRequest& req) {
|
||||
}
|
||||
|
||||
CS_HttpCameraKind HttpCameraImpl::GetKind() const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_kind;
|
||||
}
|
||||
|
||||
@@ -316,14 +316,14 @@ bool HttpCameraImpl::SetUrls(llvm::ArrayRef<std::string> urls,
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_locations.swap(locations);
|
||||
m_nextLocation = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string> HttpCameraImpl::GetUrls() const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::vector<std::string> urls;
|
||||
for (const auto& loc : m_locations) urls.push_back(loc.url);
|
||||
return urls;
|
||||
@@ -334,7 +334,7 @@ void HttpCameraImpl::CreateProperty(llvm::StringRef name,
|
||||
CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue,
|
||||
int value) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_propertyData.emplace_back(llvm::make_unique<PropertyData>(
|
||||
name, httpParam, viaSettings, kind, minimum, maximum, step, defaultValue,
|
||||
value));
|
||||
@@ -348,7 +348,7 @@ template <typename T>
|
||||
void HttpCameraImpl::CreateEnumProperty(
|
||||
llvm::StringRef name, llvm::StringRef httpParam, bool viaSettings,
|
||||
int defaultValue, int value, std::initializer_list<T> choices) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_propertyData.emplace_back(llvm::make_unique<PropertyData>(
|
||||
name, httpParam, viaSettings, CS_PROP_ENUM, 0, choices.size() - 1, 1,
|
||||
defaultValue, value));
|
||||
@@ -371,7 +371,7 @@ std::unique_ptr<PropertyImpl> HttpCameraImpl::CreateEmptyProperty(
|
||||
}
|
||||
|
||||
bool HttpCameraImpl::CacheProperties(CS_Status* status) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
|
||||
// Pretty typical set of video modes
|
||||
m_videoModes.clear();
|
||||
@@ -427,7 +427,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<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_mode = mode;
|
||||
m_streamSettingsUpdated = true;
|
||||
return true;
|
||||
@@ -456,7 +456,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<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_videoModes.clear();
|
||||
m_videoModes.emplace_back(VideoMode::kMJPEG, 640, 480, 30);
|
||||
m_videoModes.emplace_back(VideoMode::kMJPEG, 480, 360, 30);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#define CSCORE_HTTPCAMERAIMPL_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
@@ -20,6 +19,7 @@
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/StringMap.h>
|
||||
#include <support/HttpUtil.h>
|
||||
#include <support/condition_variable.h>
|
||||
#include <support/raw_istream.h>
|
||||
|
||||
#include "SourceImpl.h"
|
||||
@@ -128,10 +128,10 @@ class HttpCameraImpl : public SourceImpl {
|
||||
size_t m_nextLocation{0};
|
||||
int m_prefLocation{-1}; // preferred location
|
||||
|
||||
std::condition_variable m_sinkEnabledCond;
|
||||
wpi::condition_variable m_sinkEnabledCond;
|
||||
|
||||
llvm::StringMap<llvm::SmallString<16>> m_settings;
|
||||
std::condition_variable m_settingsCond;
|
||||
wpi::condition_variable m_settingsCond;
|
||||
|
||||
llvm::StringMap<llvm::SmallString<16>> m_streamSettings;
|
||||
std::atomic_bool m_streamSettingsUpdated{false};
|
||||
|
||||
@@ -96,18 +96,18 @@ class MjpegServerImpl::ConnThread : public wpi::SafeThread {
|
||||
llvm::StringRef GetName() { return m_name; }
|
||||
|
||||
std::shared_ptr<SourceImpl> GetSource() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_source;
|
||||
}
|
||||
|
||||
void StartStream() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_source->EnableSink();
|
||||
m_streaming = true;
|
||||
}
|
||||
|
||||
void StopStream() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_source->DisableSink();
|
||||
m_streaming = false;
|
||||
}
|
||||
@@ -783,7 +783,7 @@ void MjpegServerImpl::ConnThread::ProcessRequest() {
|
||||
|
||||
// worker thread for clients that connected to this server
|
||||
void MjpegServerImpl::ConnThread::Main() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
while (!m_stream) {
|
||||
m_cond.wait(lock);
|
||||
@@ -816,7 +816,7 @@ void MjpegServerImpl::ServerThreadMain() {
|
||||
|
||||
auto source = GetSource();
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> 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) {
|
||||
@@ -853,7 +853,7 @@ void MjpegServerImpl::ServerThreadMain() {
|
||||
}
|
||||
|
||||
void MjpegServerImpl::SetSourceImpl(std::shared_ptr<SourceImpl> source) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
for (auto& connThread : m_connThreads) {
|
||||
if (auto thr = connThread.GetThread()) {
|
||||
if (thr->m_source != source) {
|
||||
|
||||
@@ -105,7 +105,7 @@ void Notifier::Stop() { m_owner.Stop(); }
|
||||
void Notifier::Thread::Main() {
|
||||
if (m_on_start) m_on_start();
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
while (m_notifications.empty()) {
|
||||
m_cond.wait(lock);
|
||||
|
||||
@@ -22,19 +22,19 @@ SinkImpl::~SinkImpl() {
|
||||
}
|
||||
|
||||
void SinkImpl::SetDescription(llvm::StringRef description) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
llvm::StringRef SinkImpl::GetDescription(
|
||||
llvm::SmallVectorImpl<char>& buf) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
buf.append(m_description.begin(), m_description.end());
|
||||
return llvm::StringRef{buf.data(), buf.size()};
|
||||
}
|
||||
|
||||
void SinkImpl::Enable() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
++m_enabledCount;
|
||||
if (m_enabledCount == 1) {
|
||||
if (m_source) m_source->EnableSink();
|
||||
@@ -43,7 +43,7 @@ void SinkImpl::Enable() {
|
||||
}
|
||||
|
||||
void SinkImpl::Disable() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
--m_enabledCount;
|
||||
if (m_enabledCount == 0) {
|
||||
if (m_source) m_source->DisableSink();
|
||||
@@ -52,7 +52,7 @@ void SinkImpl::Disable() {
|
||||
}
|
||||
|
||||
void SinkImpl::SetEnabled(bool enabled) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (enabled && m_enabledCount == 0) {
|
||||
if (m_source) m_source->EnableSink();
|
||||
m_enabledCount = 1;
|
||||
@@ -66,7 +66,7 @@ void SinkImpl::SetEnabled(bool enabled) {
|
||||
|
||||
void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_source == source) return;
|
||||
if (m_source) {
|
||||
if (m_enabledCount > 0) m_source->DisableSink();
|
||||
@@ -82,13 +82,13 @@ void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
|
||||
}
|
||||
|
||||
std::string SinkImpl::GetError() const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (!m_source) return "no source connected";
|
||||
return m_source->GetCurFrame().GetError();
|
||||
}
|
||||
|
||||
llvm::StringRef SinkImpl::GetError(llvm::SmallVectorImpl<char>& buf) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (!m_source) return "no source connected";
|
||||
// Make a copy as it's shared data
|
||||
llvm::StringRef error = m_source->GetCurFrame().GetError();
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
#define CSCORE_SINKIMPL_H_
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include <llvm/StringRef.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "SourceImpl.h"
|
||||
|
||||
@@ -39,7 +39,7 @@ class SinkImpl {
|
||||
void SetSource(std::shared_ptr<SourceImpl> source);
|
||||
|
||||
std::shared_ptr<SourceImpl> GetSource() const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_source;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class SinkImpl {
|
||||
protected:
|
||||
virtual void SetSourceImpl(std::shared_ptr<SourceImpl> source);
|
||||
|
||||
mutable std::mutex m_mutex;
|
||||
mutable wpi::mutex m_mutex;
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
@@ -38,13 +38,13 @@ SourceImpl::~SourceImpl() {
|
||||
}
|
||||
|
||||
void SourceImpl::SetDescription(llvm::StringRef description) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
llvm::StringRef SourceImpl::GetDescription(
|
||||
llvm::SmallVectorImpl<char>& buf) const {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
buf.append(m_description.begin(), m_description.end());
|
||||
return llvm::StringRef{buf.data(), buf.size()};
|
||||
}
|
||||
@@ -58,24 +58,24 @@ void SourceImpl::SetConnected(bool connected) {
|
||||
}
|
||||
|
||||
uint64_t SourceImpl::GetCurFrameTime() {
|
||||
std::unique_lock<std::mutex> lock{m_frameMutex};
|
||||
std::unique_lock<wpi::mutex> lock{m_frameMutex};
|
||||
return m_frame.GetTime();
|
||||
}
|
||||
|
||||
Frame SourceImpl::GetCurFrame() {
|
||||
std::unique_lock<std::mutex> lock{m_frameMutex};
|
||||
std::unique_lock<wpi::mutex> lock{m_frameMutex};
|
||||
return m_frame;
|
||||
}
|
||||
|
||||
Frame SourceImpl::GetNextFrame() {
|
||||
std::unique_lock<std::mutex> lock{m_frameMutex};
|
||||
std::unique_lock<wpi::mutex> 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<std::mutex> lock{m_frameMutex};
|
||||
std::unique_lock<wpi::mutex> lock{m_frameMutex};
|
||||
auto oldTime = m_frame.GetTime();
|
||||
if (!m_frameCv.wait_for(
|
||||
lock, std::chrono::milliseconds(static_cast<int>(timeout * 1000)),
|
||||
@@ -87,7 +87,7 @@ Frame SourceImpl::GetNextFrame(double timeout) {
|
||||
|
||||
void SourceImpl::Wakeup() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{m_frameMutex};
|
||||
std::lock_guard<wpi::mutex> lock{m_frameMutex};
|
||||
m_frame = Frame{*this, llvm::StringRef{}, 0};
|
||||
}
|
||||
m_frameCv.notify_all();
|
||||
@@ -97,7 +97,7 @@ int SourceImpl::GetPropertyIndex(llvm::StringRef 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<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
int& ndx = m_properties[name];
|
||||
if (ndx == 0) {
|
||||
// create a new index
|
||||
@@ -111,7 +111,7 @@ llvm::ArrayRef<int> SourceImpl::EnumerateProperties(
|
||||
llvm::SmallVectorImpl<int>& vec, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status))
|
||||
return llvm::ArrayRef<int>{};
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
for (int i = 0; i < static_cast<int>(m_propertyData.size()); ++i) {
|
||||
if (m_propertyData[i]) vec.push_back(i + 1);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ llvm::ArrayRef<int> SourceImpl::EnumerateProperties(
|
||||
CS_PropertyKind SourceImpl::GetPropertyKind(int property) const {
|
||||
CS_Status status = 0;
|
||||
if (!m_properties_cached && !CacheProperties(&status)) return CS_PROP_NONE;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) return CS_PROP_NONE;
|
||||
return prop->propKind;
|
||||
@@ -132,7 +132,7 @@ llvm::StringRef SourceImpl::GetPropertyName(int property,
|
||||
CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status))
|
||||
return llvm::StringRef{};
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -144,7 +144,7 @@ llvm::StringRef SourceImpl::GetPropertyName(int property,
|
||||
|
||||
int SourceImpl::GetProperty(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status)) return 0;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -160,7 +160,7 @@ int SourceImpl::GetProperty(int property, CS_Status* status) const {
|
||||
|
||||
int SourceImpl::GetPropertyMin(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status)) return 0;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -171,7 +171,7 @@ int SourceImpl::GetPropertyMin(int property, CS_Status* status) const {
|
||||
|
||||
int SourceImpl::GetPropertyMax(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status)) return 0;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -182,7 +182,7 @@ int SourceImpl::GetPropertyMax(int property, CS_Status* status) const {
|
||||
|
||||
int SourceImpl::GetPropertyStep(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status)) return 0;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -193,7 +193,7 @@ int SourceImpl::GetPropertyStep(int property, CS_Status* status) const {
|
||||
|
||||
int SourceImpl::GetPropertyDefault(int property, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status)) return 0;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -207,7 +207,7 @@ llvm::StringRef SourceImpl::GetStringProperty(int property,
|
||||
CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status))
|
||||
return llvm::StringRef{};
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -226,7 +226,7 @@ std::vector<std::string> SourceImpl::GetEnumPropertyChoices(
|
||||
int property, CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status))
|
||||
return std::vector<std::string>{};
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) {
|
||||
*status = CS_INVALID_PROPERTY;
|
||||
@@ -241,7 +241,7 @@ std::vector<std::string> SourceImpl::GetEnumPropertyChoices(
|
||||
|
||||
VideoMode SourceImpl::GetVideoMode(CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status)) return VideoMode{};
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ std::vector<VideoMode> SourceImpl::EnumerateVideoModes(
|
||||
CS_Status* status) const {
|
||||
if (!m_properties_cached && !CacheProperties(status))
|
||||
return std::vector<VideoMode>{};
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_videoModes;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,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<std::mutex> lock{m_poolMutex};
|
||||
std::lock_guard<wpi::mutex> 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) {
|
||||
@@ -328,7 +328,7 @@ void SourceImpl::PutFrame(VideoMode::PixelFormat pixelFormat, int width,
|
||||
void SourceImpl::PutFrame(std::unique_ptr<Image> image, Frame::Time time) {
|
||||
// Update frame
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{m_frameMutex};
|
||||
std::lock_guard<wpi::mutex> lock{m_frameMutex};
|
||||
m_frame = Frame{*this, std::move(image), time};
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ void SourceImpl::PutFrame(std::unique_ptr<Image> image, Frame::Time time) {
|
||||
void SourceImpl::PutError(llvm::StringRef msg, Frame::Time time) {
|
||||
// Update frame
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{m_frameMutex};
|
||||
std::lock_guard<wpi::mutex> lock{m_frameMutex};
|
||||
m_frame = Frame{*this, msg, time};
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ void SourceImpl::UpdatePropertyValue(int property, bool setString, int value,
|
||||
}
|
||||
|
||||
void SourceImpl::ReleaseImage(std::unique_ptr<Image> image) {
|
||||
std::lock_guard<std::mutex> lock{m_poolMutex};
|
||||
std::lock_guard<wpi::mutex> 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.
|
||||
@@ -399,7 +399,7 @@ void SourceImpl::ReleaseImage(std::unique_ptr<Image> image) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Frame::Impl> SourceImpl::AllocFrameImpl() {
|
||||
std::lock_guard<std::mutex> lock{m_poolMutex};
|
||||
std::lock_guard<wpi::mutex> lock{m_poolMutex};
|
||||
|
||||
if (m_framesAvail.empty()) return llvm::make_unique<Frame::Impl>(*this);
|
||||
|
||||
@@ -409,7 +409,7 @@ std::unique_ptr<Frame::Impl> SourceImpl::AllocFrameImpl() {
|
||||
}
|
||||
|
||||
void SourceImpl::ReleaseFrameImpl(std::unique_ptr<Frame::Impl> impl) {
|
||||
std::lock_guard<std::mutex> lock{m_poolMutex};
|
||||
std::lock_guard<wpi::mutex> lock{m_poolMutex};
|
||||
if (m_destroyFrames) return;
|
||||
m_framesAvail.push_back(std::move(impl));
|
||||
}
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
#define CSCORE_SOURCEIMPL_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/ArrayRef.h>
|
||||
#include <llvm/StringMap.h>
|
||||
#include <llvm/StringRef.h>
|
||||
#include <support/condition_variable.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Frame.h"
|
||||
#include "Image.h"
|
||||
@@ -189,7 +189,7 @@ class SourceImpl {
|
||||
// should not be called again)
|
||||
mutable std::atomic_bool m_properties_cached{false};
|
||||
|
||||
mutable std::mutex m_mutex;
|
||||
mutable wpi::mutex m_mutex;
|
||||
|
||||
private:
|
||||
void ReleaseImage(std::unique_ptr<Image> image);
|
||||
@@ -199,13 +199,13 @@ class SourceImpl {
|
||||
std::string m_name;
|
||||
std::string m_description;
|
||||
|
||||
std::mutex m_frameMutex;
|
||||
std::condition_variable m_frameCv;
|
||||
wpi::mutex m_frameMutex;
|
||||
wpi::condition_variable m_frameCv;
|
||||
|
||||
bool m_destroyFrames{false};
|
||||
|
||||
// Pool of frames/images to reduce malloc traffic.
|
||||
std::mutex m_poolMutex;
|
||||
wpi::mutex m_poolMutex;
|
||||
std::vector<std::unique_ptr<Frame::Impl>> m_framesAvail;
|
||||
std::vector<std::unique_ptr<Image>> m_imagesAvail;
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
#define CSCORE_UNLIMITEDHANDLERESOURCE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/ArrayRef.h>
|
||||
#include <llvm/SmallVector.h>
|
||||
#include <support/atomic_static.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
namespace cs {
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace cs {
|
||||
// @tparam typeValue The type value stored in the handle
|
||||
// @tparam TMutex The mutex type to use
|
||||
template <typename THandle, typename TStruct, int typeValue,
|
||||
typename TMutex = std::mutex>
|
||||
typename TMutex = wpi::mutex>
|
||||
class UnlimitedHandleResource {
|
||||
public:
|
||||
UnlimitedHandleResource(const UnlimitedHandleResource&) = delete;
|
||||
@@ -164,7 +164,7 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::FindIf(F func) {
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue,
|
||||
typename TMutex = std::mutex>
|
||||
typename TMutex = wpi::mutex>
|
||||
class StaticUnlimitedHandleResource
|
||||
: public UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex> {
|
||||
public:
|
||||
|
||||
@@ -473,7 +473,7 @@ void UsbCameraImpl::DeviceConnect() {
|
||||
|
||||
// Restore settings
|
||||
SDEBUG3("restoring settings");
|
||||
std::unique_lock<std::mutex> lock2(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock2(m_mutex);
|
||||
for (size_t i = 0; i < m_propertyData.size(); ++i) {
|
||||
const auto prop =
|
||||
static_cast<const UsbCameraProperty*>(m_propertyData[i].get());
|
||||
@@ -588,7 +588,7 @@ bool UsbCameraImpl::DeviceStreamOff() {
|
||||
}
|
||||
|
||||
CS_StatusValue UsbCameraImpl::DeviceCmdSetMode(
|
||||
std::unique_lock<std::mutex>& lock, const Message& msg) {
|
||||
std::unique_lock<wpi::mutex>& lock, const Message& msg) {
|
||||
VideoMode newMode;
|
||||
if (msg.kind == Message::kCmdSetMode) {
|
||||
newMode.pixelFormat = msg.data[0];
|
||||
@@ -644,7 +644,7 @@ CS_StatusValue UsbCameraImpl::DeviceCmdSetMode(
|
||||
}
|
||||
|
||||
CS_StatusValue UsbCameraImpl::DeviceCmdSetProperty(
|
||||
std::unique_lock<std::mutex>& lock, const Message& msg) {
|
||||
std::unique_lock<wpi::mutex>& lock, const Message& msg) {
|
||||
bool setString = (msg.kind == Message::kCmdSetPropertyStr);
|
||||
int property = msg.data[0];
|
||||
int value = msg.data[1];
|
||||
@@ -696,7 +696,7 @@ CS_StatusValue UsbCameraImpl::DeviceCmdSetProperty(
|
||||
}
|
||||
|
||||
CS_StatusValue UsbCameraImpl::DeviceProcessCommand(
|
||||
std::unique_lock<std::mutex>& lock, const Message& msg) {
|
||||
std::unique_lock<wpi::mutex>& lock, const Message& msg) {
|
||||
if (msg.kind == Message::kCmdSetMode ||
|
||||
msg.kind == Message::kCmdSetPixelFormat ||
|
||||
msg.kind == Message::kCmdSetResolution ||
|
||||
@@ -714,7 +714,7 @@ CS_StatusValue UsbCameraImpl::DeviceProcessCommand(
|
||||
}
|
||||
|
||||
void UsbCameraImpl::DeviceProcessCommands() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
if (m_commands.empty()) return;
|
||||
while (!m_commands.empty()) {
|
||||
auto msg = std::move(m_commands.back());
|
||||
@@ -793,7 +793,7 @@ void UsbCameraImpl::DeviceCacheMode() {
|
||||
vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (DoIoctl(fd, VIDIOC_G_FMT, &vfmt) != 0) {
|
||||
SERROR("could not read current video mode");
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_mode = VideoMode{VideoMode::kMJPEG, 320, 240, 30};
|
||||
return;
|
||||
}
|
||||
@@ -859,7 +859,7 @@ void UsbCameraImpl::DeviceCacheMode() {
|
||||
|
||||
// Save to global mode
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_mode.pixelFormat = pixelFormat;
|
||||
m_mode.width = width;
|
||||
m_mode.height = height;
|
||||
@@ -889,7 +889,7 @@ void UsbCameraImpl::DeviceCacheProperty(
|
||||
rawProp->name = "raw_" + perProp->name;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
int* rawIndex = &m_properties[rawProp->name];
|
||||
bool newRaw = *rawIndex == 0;
|
||||
UsbCameraProperty* oldRawProp =
|
||||
@@ -1048,7 +1048,7 @@ void UsbCameraImpl::DeviceCacheVideoModes() {
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_videoModes.swap(modes);
|
||||
}
|
||||
Notifier::GetInstance().NotifySource(*this, CS_SOURCE_VIDEOMODES_UPDATED);
|
||||
@@ -1063,14 +1063,14 @@ CS_StatusValue UsbCameraImpl::SendAndWait(Message&& msg) const {
|
||||
|
||||
// Add the message to the command queue
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_commands.emplace_back(std::move(msg));
|
||||
}
|
||||
|
||||
// Signal the camera thread
|
||||
if (eventfd_write(fd, 1) < 0) return CS_SOURCE_IS_DISCONNECTED;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
// Did we get a response to *our* request?
|
||||
auto it =
|
||||
@@ -1098,7 +1098,7 @@ void UsbCameraImpl::Send(Message&& msg) const {
|
||||
|
||||
// Add the message to the command queue
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_commands.emplace_back(std::move(msg));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <llvm/STLExtras.h>
|
||||
#include <llvm/SmallVector.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
#include <support/condition_variable.h>
|
||||
#include <support/mutex.h>
|
||||
#include <support/raw_istream.h>
|
||||
|
||||
#include "SourceImpl.h"
|
||||
@@ -121,11 +123,11 @@ class UsbCameraImpl : public SourceImpl {
|
||||
void DeviceCacheVideoModes();
|
||||
|
||||
// Command helper functions
|
||||
CS_StatusValue DeviceProcessCommand(std::unique_lock<std::mutex>& lock,
|
||||
CS_StatusValue DeviceProcessCommand(std::unique_lock<wpi::mutex>& lock,
|
||||
const Message& msg);
|
||||
CS_StatusValue DeviceCmdSetMode(std::unique_lock<std::mutex>& lock,
|
||||
CS_StatusValue DeviceCmdSetMode(std::unique_lock<wpi::mutex>& lock,
|
||||
const Message& msg);
|
||||
CS_StatusValue DeviceCmdSetProperty(std::unique_lock<std::mutex>& lock,
|
||||
CS_StatusValue DeviceCmdSetProperty(std::unique_lock<wpi::mutex>& lock,
|
||||
const Message& msg);
|
||||
|
||||
// Property helper functions
|
||||
@@ -173,7 +175,7 @@ class UsbCameraImpl : public SourceImpl {
|
||||
// Message queues
|
||||
mutable std::vector<Message> m_commands;
|
||||
mutable std::vector<std::pair<std::thread::id, CS_StatusValue>> m_responses;
|
||||
mutable std::condition_variable m_responseCv;
|
||||
mutable wpi::condition_variable m_responseCv;
|
||||
};
|
||||
|
||||
} // namespace cs
|
||||
|
||||
@@ -246,7 +246,7 @@ std::unique_ptr<UsbCameraProperty> UsbCameraProperty::DeviceQuery(int fd,
|
||||
return prop;
|
||||
}
|
||||
|
||||
bool UsbCameraProperty::DeviceGet(std::unique_lock<std::mutex>& lock, int fd) {
|
||||
bool UsbCameraProperty::DeviceGet(std::unique_lock<wpi::mutex>& lock, int fd) {
|
||||
if (fd < 0) return true;
|
||||
unsigned idCopy = id;
|
||||
int rv = 0;
|
||||
@@ -279,14 +279,14 @@ bool UsbCameraProperty::DeviceGet(std::unique_lock<std::mutex>& lock, int fd) {
|
||||
return rv >= 0;
|
||||
}
|
||||
|
||||
bool UsbCameraProperty::DeviceSet(std::unique_lock<std::mutex>& lock,
|
||||
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock,
|
||||
int fd) const {
|
||||
// Make a copy of the string as we're about to release the lock
|
||||
llvm::SmallString<128> valueStrCopy{valueStr};
|
||||
return DeviceSet(lock, fd, value, valueStrCopy);
|
||||
}
|
||||
|
||||
bool UsbCameraProperty::DeviceSet(std::unique_lock<std::mutex>& lock, int fd,
|
||||
bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd,
|
||||
int newValue,
|
||||
llvm::StringRef newValueStr) const {
|
||||
if (fd < 0) return true;
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "PropertyImpl.h"
|
||||
|
||||
@@ -48,9 +49,9 @@ class UsbCameraProperty : public PropertyImpl {
|
||||
|
||||
static std::unique_ptr<UsbCameraProperty> DeviceQuery(int fd, __u32* id);
|
||||
|
||||
bool DeviceGet(std::unique_lock<std::mutex>& lock, int fd);
|
||||
bool DeviceSet(std::unique_lock<std::mutex>& lock, int fd) const;
|
||||
bool DeviceSet(std::unique_lock<std::mutex>& lock, int fd, int newValue,
|
||||
bool DeviceGet(std::unique_lock<wpi::mutex>& lock, int fd);
|
||||
bool DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd) const;
|
||||
bool DeviceSet(std::unique_lock<wpi::mutex>& lock, int fd, int newValue,
|
||||
llvm::StringRef newValueStr) const;
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user