From patchwork Wed Apr 1 09:15:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 3365 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C7EA629B9 for ; Wed, 1 Apr 2020 11:16:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wYZzEi/+"; dkim-atps=neutral Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8DC23A35; Wed, 1 Apr 2020 11:16:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585732560; bh=JWb2qxK20Bve81hLYR1HoTxArfxYedUjC7sXo2lZhFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wYZzEi/+WWeiesHD1VAUdA9Ei96HOF+bXGzDaGR6OitM1CMtiwccq6m+9V72AuEgD x6j8dAkEioisjHOj+iDOVP6VO0wD9taTqHu5UVaWGgXZwFbM61N4XR/igD6oR4RG4L tGhPwCUX46M1y+MM2pcJCrk3a09NNeuwGRslznLQ= From: Kieran Bingham To: libcamera devel Date: Wed, 1 Apr 2020 10:15:51 +0100 Message-Id: <20200401091553.28187-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> References: <20200401091553.28187-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4.1 1/3] libcamera: Define {unique, shared}_ptr helpers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2020 09:16:01 -0000 The politics in libcamera has become fuzzy and hazed. It's no longer clear as to which side of the fence any of our code belongs. Clarify the opinions of the codebase to make the intentions clear to the compiler. Signed-off-by: Kieran Bingham --- include/libcamera/meson.build | 1 + include/libcamera/pointers.h | 18 ++++++++++++++++++ src/libcamera/include/v4l2_videodevice.h | 11 ++++++----- src/libcamera/v4l2_videodevice.cpp | 14 +++++++------- 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 include/libcamera/pointers.h diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 23c01d3837ba..ba48e44492f8 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -12,6 +12,7 @@ libcamera_api = files([ 'logging.h', 'object.h', 'pixelformats.h', + 'pointers.h', 'request.h', 'signal.h', 'span.h', diff --git a/include/libcamera/pointers.h b/include/libcamera/pointers.h new file mode 100644 index 000000000000..637c0c30ff83 --- /dev/null +++ b/include/libcamera/pointers.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Kieran Bingham + * + * pointers.h - pointer declarations + */ + +#ifndef __LIBCAMERA_POINTERS_H__ +#define __LIBCAMERA_POINTERS_H__ + +namespace libcamera { + +#define capitalist_ptr unique_ptr +#define socialist_ptr shared_ptr + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_POINTERS_H__ */ diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 7d7c4a9e6ebd..d059b2841717 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "formats.h" @@ -111,7 +112,7 @@ class V4L2BufferCache { public: V4L2BufferCache(unsigned int numEntries); - V4L2BufferCache(const std::vector> &buffers); + V4L2BufferCache(const std::vector> &buffers); ~V4L2BufferCache(); int get(const FrameBuffer &buffer); @@ -213,9 +214,9 @@ public: int setCompose(Rectangle *rect); int allocateBuffers(unsigned int count, - std::vector> *buffers); + std::vector> *buffers); int exportBuffers(unsigned int count, - std::vector> *buffers); + std::vector> *buffers); int importBuffers(unsigned int count); int releaseBuffers(); @@ -253,8 +254,8 @@ private: int requestBuffers(unsigned int count, enum v4l2_memory memoryType); int createBuffers(unsigned int count, - std::vector> *buffers); - std::unique_ptr createBuffer(unsigned int index); + std::vector> *buffers); + std::capitalist_ptr createBuffer(unsigned int index); FileDescriptor exportDmabufFd(unsigned int index, unsigned int plane); void bufferAvailable(EventNotifier *notifier); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index eb33a68e50d6..d7b08a787fdc 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -176,10 +176,10 @@ V4L2BufferCache::V4L2BufferCache(unsigned int numEntries) * implement buffer export, with all buffers added to the cache when they are * allocated. */ -V4L2BufferCache::V4L2BufferCache(const std::vector> &buffers) +V4L2BufferCache::V4L2BufferCache(const std::vector> &buffers) : lastUsedCounter_(1), missCounter_(0) { - for (const std::unique_ptr &buffer : buffers) + for (const std::capitalist_ptr &buffer : buffers) cache_.emplace_back(true, lastUsedCounter_.fetch_add(1, std::memory_order_acq_rel), buffer->planes()); @@ -1187,7 +1187,7 @@ int V4L2VideoDevice::requestBuffers(unsigned int count, * \retval -EBUSY buffers have already been allocated or imported */ int V4L2VideoDevice::allocateBuffers(unsigned int count, - std::vector> *buffers) + std::vector> *buffers) { int ret = createBuffers(count, buffers); if (ret < 0) @@ -1231,7 +1231,7 @@ int V4L2VideoDevice::allocateBuffers(unsigned int count, * \retval -EBUSY buffers have already been allocated or imported */ int V4L2VideoDevice::exportBuffers(unsigned int count, - std::vector> *buffers) + std::vector> *buffers) { int ret = createBuffers(count, buffers); if (ret < 0) @@ -1243,7 +1243,7 @@ int V4L2VideoDevice::exportBuffers(unsigned int count, } int V4L2VideoDevice::createBuffers(unsigned int count, - std::vector> *buffers) + std::vector> *buffers) { if (cache_) { LOG(V4L2, Error) << "Buffers already allocated"; @@ -1255,7 +1255,7 @@ int V4L2VideoDevice::createBuffers(unsigned int count, return ret; for (unsigned i = 0; i < count; ++i) { - std::unique_ptr buffer = createBuffer(i); + std::capitalist_ptr buffer = createBuffer(i); if (!buffer) { LOG(V4L2, Error) << "Unable to create buffer"; @@ -1271,7 +1271,7 @@ int V4L2VideoDevice::createBuffers(unsigned int count, return count; } -std::unique_ptr V4L2VideoDevice::createBuffer(unsigned int index) +std::capitalist_ptr V4L2VideoDevice::createBuffer(unsigned int index) { struct v4l2_plane v4l2Planes[VIDEO_MAX_PLANES] = {}; struct v4l2_buffer buf = {};