android: Consolidate mutex classes to Mutex and MutexLocker

std::mutex and std::unique_lock are used in android directories,
mixing Mutex and MutexLocker. This consolidates them to Mutex
and MutexLocker.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Hirokazu Honda 2021-12-01 16:53:38 +09:00 committed by Laurent Pinchart
parent 923cf7f40a
commit 3536473e06
5 changed files with 11 additions and 16 deletions

View file

@ -9,7 +9,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex>
#include <queue> #include <queue>
#include <vector> #include <vector>

View file

@ -8,7 +8,6 @@
#pragma once #pragma once
#include <map> #include <map>
#include <mutex>
#include <stddef.h> #include <stddef.h>
#include <tuple> #include <tuple>
#include <vector> #include <vector>
@ -18,6 +17,7 @@
#include <system/camera_metadata.h> #include <system/camera_metadata.h>
#include <libcamera/base/class.h> #include <libcamera/base/class.h>
#include <libcamera/base/thread.h>
#include <libcamera/camera_manager.h> #include <libcamera/camera_manager.h>
@ -44,9 +44,6 @@ public:
private: private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager) LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager)
using Mutex = std::mutex;
using MutexLocker = std::unique_lock<std::mutex>;
static constexpr unsigned int firstExternalCameraId_ = 1000; static constexpr unsigned int firstExternalCameraId_ = 1000;
CameraHalManager(); CameraHalManager();
@ -64,7 +61,7 @@ private:
const camera_module_callbacks_t *callbacks_; const camera_module_callbacks_t *callbacks_;
std::vector<std::unique_ptr<CameraDevice>> cameras_; std::vector<std::unique_ptr<CameraDevice>> cameras_;
std::map<std::string, unsigned int> cameraIdsMap_; std::map<std::string, unsigned int> cameraIdsMap_;
Mutex mutex_; libcamera::Mutex mutex_;
unsigned int numInternalCameras_; unsigned int numInternalCameras_;
unsigned int nextExternalCameraId_; unsigned int nextExternalCameraId_;

View file

@ -9,10 +9,10 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex>
#include <vector> #include <vector>
#include <libcamera/base/class.h> #include <libcamera/base/class.h>
#include <libcamera/base/thread.h>
#include <libcamera/camera.h> #include <libcamera/camera.h>
#include <libcamera/framebuffer.h> #include <libcamera/framebuffer.h>
@ -58,7 +58,7 @@ public:
/* Keeps track of streams requiring post-processing. */ /* Keeps track of streams requiring post-processing. */
std::map<CameraStream *, StreamBuffer *> pendingStreamsToProcess_; std::map<CameraStream *, StreamBuffer *> pendingStreamsToProcess_;
std::mutex streamsProcessMutex_; libcamera::Mutex streamsProcessMutex_;
Camera3RequestDescriptor(libcamera::Camera *camera, Camera3RequestDescriptor(libcamera::Camera *camera,
const camera3_capture_request_t *camera3Request); const camera3_capture_request_t *camera3Request);

View file

@ -119,7 +119,7 @@ int CameraStream::configure()
if (type_ == Type::Internal) { if (type_ == Type::Internal) {
allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera()); allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());
mutex_ = std::make_unique<std::mutex>(); mutex_ = std::make_unique<Mutex>();
int ret = allocator_->allocate(stream()); int ret = allocator_->allocate(stream());
if (ret < 0) if (ret < 0)
@ -208,7 +208,7 @@ FrameBuffer *CameraStream::getBuffer()
if (!allocator_) if (!allocator_)
return nullptr; return nullptr;
std::lock_guard<std::mutex> locker(*mutex_); MutexLocker locker(*mutex_);
if (buffers_.empty()) { if (buffers_.empty()) {
LOG(HAL, Error) << "Buffer underrun"; LOG(HAL, Error) << "Buffer underrun";
@ -226,7 +226,7 @@ void CameraStream::putBuffer(FrameBuffer *buffer)
if (!allocator_) if (!allocator_)
return; return;
std::lock_guard<std::mutex> locker(*mutex_); MutexLocker locker(*mutex_);
buffers_.push_back(buffer); buffers_.push_back(buffer);
} }
@ -239,7 +239,7 @@ CameraStream::PostProcessorWorker::PostProcessorWorker(PostProcessor *postProces
CameraStream::PostProcessorWorker::~PostProcessorWorker() CameraStream::PostProcessorWorker::~PostProcessorWorker()
{ {
{ {
libcamera::MutexLocker lock(mutex_); MutexLocker lock(mutex_);
state_ = State::Stopped; state_ = State::Stopped;
} }
@ -250,7 +250,7 @@ CameraStream::PostProcessorWorker::~PostProcessorWorker()
void CameraStream::PostProcessorWorker::start() void CameraStream::PostProcessorWorker::start()
{ {
{ {
libcamera::MutexLocker lock(mutex_); MutexLocker lock(mutex_);
ASSERT(state_ != State::Running); ASSERT(state_ != State::Running);
state_ = State::Running; state_ = State::Running;
} }
@ -308,7 +308,7 @@ void CameraStream::PostProcessorWorker::run()
void CameraStream::PostProcessorWorker::flush() void CameraStream::PostProcessorWorker::flush()
{ {
libcamera::MutexLocker lock(mutex_); MutexLocker lock(mutex_);
state_ = State::Flushing; state_ = State::Flushing;
lock.unlock(); lock.unlock();

View file

@ -8,7 +8,6 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <mutex>
#include <queue> #include <queue>
#include <vector> #include <vector>
@ -173,7 +172,7 @@ private:
* The class has to be MoveConstructible as instances are stored in * The class has to be MoveConstructible as instances are stored in
* an std::vector in CameraDevice. * an std::vector in CameraDevice.
*/ */
std::unique_ptr<std::mutex> mutex_; std::unique_ptr<libcamera::Mutex> mutex_;
std::unique_ptr<PostProcessor> postProcessor_; std::unique_ptr<PostProcessor> postProcessor_;
std::unique_ptr<PostProcessorWorker> worker_; std::unique_ptr<PostProcessorWorker> worker_;