From patchwork Tue Aug 11 13:00:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27755 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2A4F8C32FE for ; Tue, 11 Aug 2026 13:00:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1AEC26827E; Tue, 11 Aug 2026 15:00:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="C3t4/CfX"; dkim-atps=neutral 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 DBA2C68260 for ; Tue, 11 Aug 2026 15:00:46 +0200 (CEST) Received: from pb-laptop.local (185.221.141.208.nat.pool.zt.hu [185.221.141.208]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1117D1E99 for ; Tue, 11 Aug 2026 14:59:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1786453172; bh=4yD+yhpiKrZRksGje93mRTG+SyCDTDmNQx3KfAWmBT4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=C3t4/CfXrBvKaCYS8iGjhKM8iS3LDJ+JMCs1/HoOp77DwWL+QvB0KRZXgyINVnygq CNKCZfrckQYMn/L2mcXLY8a1Bj/hZGHQ6T1h99flq7udKXlz8PIaicSC1M169EcmE3 nx8ufPPYFxmw/KPFFmBPjtYbOr5jcQoxI2I5lClE= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v3 5/8] libcamera: egl: Add `assertThread()` Date: Tue, 11 Aug 2026 15:00:39 +0200 Message-ID: <20260811130042.213139-6-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260811130042.213139-1-barnabas.pocze@ideasonboard.com> References: <20260811130042.213139-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a public function that does the thread check, and use that everywhere. This is very similar to `Object::assertThreadBound()`, but without actually making `eGL` an `Object`. That would be an option, but handling the moving between threads with the egl context is not easily implementable currently. Signed-off-by: Barnabás Pőcze Reviewed-by: Milan Zamazal Reviewed-by: Jacopo Mondi --- include/libcamera/internal/egl.h | 6 ++++++ src/libcamera/egl.cpp | 30 +++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index fb77225ac4..13df65e6b2 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -14,6 +14,7 @@ #include #include +#include #include /* @@ -126,6 +127,11 @@ public: void syncOutput(); void flushOutput(); + void assertThread() const + { + ASSERT(tid_ == Thread::currentId()); + } + private: LIBCAMERA_DISABLE_COPY_AND_MOVE(eGL) diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 3de5fab816..2a1f577845 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -89,7 +89,7 @@ eGL::~eGL() */ void eGL::syncOutput() { - ASSERT(tid_ == Thread::currentId()); + assertThread(); glFinish(); } @@ -102,11 +102,19 @@ void eGL::syncOutput() */ void eGL::flushOutput() { - ASSERT(tid_ == Thread::currentId()); + assertThread(); glFlush(); } +/** + * \fn eGL::assertThread() + * \brief Assert that the execution is in the right thread + * + * Asserts that the execution is in the thread for which + * the created EGL context has been made current. + */ + /** * \brief Attach a texture to a frame-buffer-object * @@ -167,7 +175,7 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) EGLint drm_format; int ret = 0; - ASSERT(tid_ == Thread::currentId()); + assertThread(); switch (eglImage.format_) { case GL_RED: @@ -242,7 +250,7 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output) */ int eGL::createInputDMABufTexture2D(eGLImage &eglImage, int fd) { - ASSERT(tid_ == Thread::currentId()); + assertThread(); return createDMABufTexture2D(eglImage, fd, false); } @@ -261,7 +269,7 @@ int eGL::createInputDMABufTexture2D(eGLImage &eglImage, int fd) */ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) { - ASSERT(tid_ == Thread::currentId()); + assertThread(); return createDMABufTexture2D(eglImage, fd, true); } @@ -278,7 +286,7 @@ int eGL::createOutputDMABufTexture2D(eGLImage &eglImage, int fd) */ void eGL::createTexture2D(eGLImage &eglImage, void *data) { - ASSERT(tid_ == Thread::currentId()); + assertThread(); activateBindTexture(eglImage); @@ -331,7 +339,7 @@ EGLDisplay eGL::probeDisplay() */ void eGL::updateTexture2D(eGLImage &eglImage, void *data) { - ASSERT(tid_ == Thread::currentId()); + assertThread(); activateBindTexture(eglImage); @@ -445,7 +453,7 @@ fail: */ void eGL::makeCurrent() { - ASSERT(tid_ == Thread::currentId()); + assertThread(); if (eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_) != EGL_TRUE) { LOG(eGL, Error) << "eglMakeCurrent fail"; @@ -523,7 +531,7 @@ int eGL::compileShader(int shaderType, GLuint &shaderId, GLint success; size_t i; - ASSERT(tid_ == Thread::currentId()); + assertThread(); auto count = 1 + shaderEnv.size(); auto shaderSourceData = std::make_unique(count); @@ -570,7 +578,7 @@ void eGL::dumpShaderSource(GLuint shaderId) { GLint shaderLength = 0; - ASSERT(tid_ == Thread::currentId()); + assertThread(); glGetShaderiv(shaderId, GL_SHADER_SOURCE_LENGTH, &shaderLength); @@ -603,7 +611,7 @@ int eGL::linkProgram(GLuint &programId, GLuint vertexshaderId, GLuint fragmentsh GLenum err; int ret = -ENODEV; - ASSERT(tid_ == Thread::currentId()); + assertThread(); programId = glCreateProgram(); if (!programId) {