From patchwork Mon Apr 26 07:46:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shubhanshu Saxena X-Patchwork-Id: 27413 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp3742885iob; Mon, 26 Apr 2021 00:50:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbs014d7cf3WfzIw02wJiP38rxHW/65k2E6UAMV/PX6NyIOpRZEnjcwh9l5kUa4h48Aham X-Received: by 2002:aa7:c456:: with SMTP id n22mr19340549edr.255.1619423411215; Mon, 26 Apr 2021 00:50:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619423411; cv=none; d=google.com; s=arc-20160816; b=uPr7fUR6YSTSS5qPsTalTy8ZAAvh6sohVuBdmiQJU7Oz1lbSlQs/0N9ckL96GDXd5M 35Tsv0gsgQbEIAifrpvOJL8hwUZxw6oXK72T7YfJt5IcDV7aeI1OA6+d+3hk0QLuICxQ rMVMvM0J+wl+d9gb1zsfVqaFcgMF1bDT3SIHNDpkhCjqXRaj0cjWw5aI1hC4ewFdph0z Fu4aXJuYO4NT+NI3e/2ublNt84Mtm8bMMacz9yRQz7tcAljqjk0GO2u1cWdJADq8FzvZ TZdOa/u9VfsiLuS1yLzAVqDrgm49CG56ef+ndgeQhNBMNqb74bMZIYHv4cXOcEZ8OdwS dRCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=S0SfNGzOrzVf39sTScoIOuZWzDMmUzg4LzJM6sgBPhk=; b=I4Kbs8wF3LEIL0N0S1Lbeyt/oNSXLcP7Yln5N6ft8xxr+m4vHUo3bIcII1ymx82Axw RzAAmJTtbXHxoBh17s3wETSUnmUVvd6B5TBxjd74uV8uLlFQg7q6/r0daQQoywU3/kVL zA3g68Rt/jyDUASGr+Fq1u4PO5w4pQHReWRfhApzn70D4BENPw79Idhq4BCpk13NS7k6 hd3m6fYikmEPj8maofXH8CjbrujtRoV6CETYG/HZ/kxRg58OmHVPrBgNp9GUJNo75/ME g+lJRe4Wr01nEXy3aFEFaxoXxZiXHQ+ToVEKCxULGxlXg+8kpW6gUTAgCzKljHemmw4G GITw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=IfsVGUK+; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id kw5si13008763ejc.436.2021.04.26.00.50.10; Mon, 26 Apr 2021 00:50:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=IfsVGUK+; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 35444689966; Mon, 26 Apr 2021 10:50:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9227689806 for ; Mon, 26 Apr 2021 10:50:00 +0300 (EEST) Received: by mail-pf1-f170.google.com with SMTP id 10so2956174pfl.1 for ; Mon, 26 Apr 2021 00:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ODsXts1iKtxlpm8DyHo6/wrxPSJjn6f/eXhLkGbgdr4=; b=IfsVGUK+fdzXVg+aoo6+92br6i6attBk/l0X9zlTFBKOvsAVBsRUPd5eZUcPs53tMF j2OcVyIuwQfEQAMjyYPwe6T12Ai1m7X54uOaWt1DK3LTf1qMwe/EYBoeKkkuHoy0ODje B2kmHBeT9kRMmVAfCRUfzuKWyykfcmgYJfX2YzTKYSc+okpe+26S0BwO0OAipXVRfD9f 4fKn18qcDrGeoBRPuxGy5HFqrKJ2ZhY5JkJLoNBLNNZHLUexflqW+qOiqTBmvm10lTVv yls8RpQC2UI+ZGCv7a+ITaf3NqpmJpMCXxoho+jwQsm5GF5tJtFUeKZsKQWZD3s2pAuP 5OMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ODsXts1iKtxlpm8DyHo6/wrxPSJjn6f/eXhLkGbgdr4=; b=WDOqWPkmSQbVtz3QleLhMYOWOTdVvQmyjY0qflOswixSq5qxzLURFQZtNh/Ny9BiZV dok05XgLFIuTzDW+N6PKq6Hu/Mjhfw1D5/LQxUwi6p4Jt26mZ9arBU+8L7JY4QtvEBB4 Hd1pAHBDAf31zwAk+UTQKlBYejwv9l1nxLi1gZ4axIwE7bqNCNi/SG8SgRouZZpDegse HnK6jCir7UL6dApasaUvEutU4gHD6BznAOoCGhjcYN3b0eS7mrp+NiDjcpnOtDoEDJ9Y GIc+gPhTm7wANkz8Yb+0Q5MIr6sFD7juYbT7KvxGtR1+NBlxSLUtWkHeWMq8hFIqmhwa BKog== X-Gm-Message-State: AOAM530RuPr2YHO104A2X4VLkhOxyfSomgfSqJuPlRkqgkfhTlzqZJOw y0B/xVuATVZxJw3uspEtRJmfpqXNjOIsgw== X-Received: by 2002:a63:eb12:: with SMTP id t18mr15839094pgh.349.1619423398681; Mon, 26 Apr 2021 00:49:58 -0700 (PDT) Received: from Pavilion-x360.bbrouter ([103.157.221.194]) by smtp.googlemail.com with ESMTPSA id l18sm13454588pjq.33.2021.04.26.00.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 00:49:58 -0700 (PDT) From: Shubhanshu Saxena To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Apr 2021 13:16:50 +0530 Message-Id: <20210426074649.6725-1-shubhanshu.e01@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavfi/dnn/safe_queue.h: Add Documentation to SafeQueue X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Shubhanshu Saxena Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KmBLmt4aX1jY Documentation for SafeQueue Signed-off-by: Shubhanshu Saxena --- libavfilter/dnn/safe_queue.h | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/libavfilter/dnn/safe_queue.h b/libavfilter/dnn/safe_queue.h index 36d6daabaf..577a02e24d 100644 --- a/libavfilter/dnn/safe_queue.h +++ b/libavfilter/dnn/safe_queue.h @@ -21,16 +21,76 @@ #ifndef AVFILTER_DNN_SAFE_QUEUE_H #define AVFILTER_DNN_SAFE_QUEUE_H +/** + * Double-ended queue with mutex locks ensuring + * data consistency while multithreading. + */ typedef struct SafeQueue SafeQueue; +/** + * @brief Create and initialize a SafeQueue instance. + * + * @return Pointer to the SafeQueue + * @retval NULL if initialization fails + */ SafeQueue *ff_safe_queue_create(void); + +/** + * @brief Destroy the SafeQueue instance. + * It also frees all elements of the queue, + * destroys the mutex and condition variable. + */ void ff_safe_queue_destroy(SafeQueue *sq); +/** + * @brief Return the length of the SafeQueue + */ size_t ff_safe_queue_size(SafeQueue *sq); +/** + * @brief Add data to the head of queue in the + * SafeQueue after locking mutex. After adding + * the data, it signals the condition variable + * and unlocks the mutex. It increases the length + * of queue in the SafeQueue by one. + * + * @param sq pointer to the SafeQueue + * @param v data to be added + * @return The length of the queue + * @retval 0 if the queue is not initialized + * @retval -1 if new entry cannot be created + */ int ff_safe_queue_push_front(SafeQueue *sq, void *v); + +/** + * @brief Add data to the tail of queue in the + * SafeQueue after locking mutex. After adding + * the data, it signals the condition variable + * and unlocks the mutex. It increases the length + * of queue in the SafeQueue by one. + * + * @param sq pointer to the SafeQueue + * @param v data to be added + * @return The length of the queue + * @retval 0 if the queue is not initialized + * @retval -1 if new entry cannot be created + */ int ff_safe_queue_push_back(SafeQueue *sq, void *v); +/** + * @brief Remove and free first element from + * the queue in SafeQueue. Before removing, it + * waits for the condition variable to signal and + * acquires the mutex. Finally, it signals the + * condition and unlocks the mutex. + * It shrinks the length of queue in the SafeQueue + * by one. + * + * @param sq pointer to the SafeQueue. + * @return The value of first element as void. + * If a null pointer or empty queue is passed, + * it returns NULL + */ void *ff_safe_queue_pop_front(SafeQueue *sq); #endif