summaryrefslogtreecommitdiff
path: root/src/v4l2/v4l2_compat_manager.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-01-20 01:09:34 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-02-13 12:34:42 +0200
commit8a8502ec0ea5e64a0c44eb18aac0ecd4b6771e6b (patch)
treed8b00138032054e427c55e8ed0d38014b7873ef3 /src/v4l2/v4l2_compat_manager.cpp
parentb3b0d0a2e92fefe8298ba37f78be4d2364a75f56 (diff)
v4l2: Remove internal thread
Now that libcamera creates threads internally and doesn't rely on an application-provided event loop, remove the thread from the V4L2 compatibility layer. The split between the V4L2CameraProxy and V4L2Camera classes is still kept to separate the V4L2 adaptation from camera operation. This may be further refactored later. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/v4l2/v4l2_compat_manager.cpp')
-rw-r--r--src/v4l2/v4l2_compat_manager.cpp48
1 files changed, 13 insertions, 35 deletions
diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp
index f5a7b2ac..961d06b3 100644
--- a/src/v4l2/v4l2_compat_manager.cpp
+++ b/src/v4l2/v4l2_compat_manager.cpp
@@ -37,7 +37,7 @@ void get_symbol(T &func, const char *name)
} /* namespace */
V4L2CompatManager::V4L2CompatManager()
- : cm_(nullptr), initialized_(false)
+ : cm_(nullptr)
{
get_symbol(fops_.openat, "openat");
get_symbol(fops_.dup, "dup");
@@ -52,24 +52,15 @@ V4L2CompatManager::~V4L2CompatManager()
devices_.clear();
mmaps_.clear();
- if (isRunning()) {
- exit(0);
- /* \todo Wait with a timeout, just in case. */
- wait();
+ if (cm_) {
+ proxies_.clear();
+ cm_->stop();
+ delete cm_;
+ cm_ = nullptr;
}
}
-int V4L2CompatManager::init()
-{
- start();
-
- MutexLocker locker(mutex_);
- cv_.wait(locker, [&] { return initialized_; });
-
- return 0;
-}
-
-void V4L2CompatManager::run()
+int V4L2CompatManager::start()
{
cm_ = new CameraManager();
@@ -77,7 +68,9 @@ void V4L2CompatManager::run()
if (ret) {
LOG(V4L2Compat, Error) << "Failed to start camera manager: "
<< strerror(-ret);
- return;
+ delete cm_;
+ cm_ = nullptr;
+ return ret;
}
LOG(V4L2Compat, Debug) << "Started camera manager";
@@ -93,22 +86,7 @@ void V4L2CompatManager::run()
++index;
}
- /*
- * libcamera has been initialized. Unlock the init() caller as we're
- * now ready to handle calls from the framework.
- */
- mutex_.lock();
- initialized_ = true;
- mutex_.unlock();
- cv_.notify_one();
-
- /* Now start processing events and messages. */
- exec();
-
- proxies_.clear();
- cm_->stop();
- delete cm_;
- cm_ = nullptr;
+ return 0;
}
V4L2CompatManager *V4L2CompatManager::instance()
@@ -159,8 +137,8 @@ int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mod
major(statbuf.st_rdev) != 81)
return fd;
- if (!isRunning())
- init();
+ if (!cm_)
+ start();
ret = getCameraIndex(fd);
if (ret < 0) {