From patchwork Thu Mar 3 22:59:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 63496 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp160489lbc; Thu, 3 Mar 2016 14:59:55 -0800 (PST) X-Received: by 10.140.166.6 with SMTP id m6mr6940434qhm.70.1457045995063; Thu, 03 Mar 2016 14:59:55 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 188si787837qhy.96.2016.03.03.14.59.54; Thu, 03 Mar 2016 14:59:55 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3F58C667A6; Thu, 3 Mar 2016 22:59:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 58957619C1; Thu, 3 Mar 2016 22:59:52 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 41C4C61BBB; Thu, 3 Mar 2016 22:59:50 +0000 (UTC) Received: from mail-qg0-f49.google.com (mail-qg0-f49.google.com [209.85.192.49]) by lists.linaro.org (Postfix) with ESMTPS id 400A3619BF for ; Thu, 3 Mar 2016 22:59:49 +0000 (UTC) Received: by mail-qg0-f49.google.com with SMTP id w104so30259277qge.1 for ; Thu, 03 Mar 2016 14:59:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H1a5yR2XoB6dA3uXV+X5jyzwKUBrFwvAcb9fpUOecjg=; b=CayiyeAKNrJufk4xkBdPALEil2dayBnqiz8v1C6r+tmvt24wi2CZ2pNT0w6Mt+sX80 hFU3uby+iCCZ046IZfayS2qesgrw60aG+S1r6rWXPK6/ljtVAiQsGWP2lG8Lf2pa7Cfj /5qCA1gbY8T+vyn1fnniwHwlqNuUpV9vB1z/UeABUWAkIkYzBd7dDyev4OuLJaMszX9r kgx6dpV3fvQsXMRpJC7EqUxE06iHJtoDkKf8++X5ySQO0l8uZzY1KuabeS01J1P70NUr dT2Unrd41x2gp1vzWAD0T3SRZxdRI/PbvLeFFzVjcN+kSae85eAIoGT/Wr20fakizaF2 iKAA== X-Gm-Message-State: AD7BkJKfAjBhUo4RoW7Sa/l+FfDR+VzOQ++gXxy/Zqj5pibEwTVw6tgSBuM4jUnPN01wJqTYA54= X-Received: by 10.140.219.134 with SMTP id p128mr6771534qhb.80.1457045989028; Thu, 03 Mar 2016 14:59:49 -0800 (PST) Received: from Ubuntu15.localdomain ([64.88.227.134]) by smtp.gmail.com with ESMTPSA id y200sm332815qka.48.2016.03.03.14.59.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Mar 2016 14:59:48 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 3 Mar 2016 16:59:26 -0600 Message-Id: <1457045968-31405-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 1/3] api: rwlock: add trylock variants for rwlock and rwlock_recursive X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Add the following APIs: - odp_rwlock_read_trylock() - odp_rwlock_write_trylock() - odp_rwlock_recursive_read_trylock() - odp_rwlock_recursive_write_trylock() Suggested-by: Sorin Vultureanu @ s 1 Signed-off-by: Bill Fischofer --- include/odp/api/spec/rwlock.h | 23 ++++++++++++++++++++++- include/odp/api/spec/rwlock_recursive.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/odp/api/spec/rwlock.h b/include/odp/api/spec/rwlock.h index 54f426f..ef91e4a 100644 --- a/include/odp/api/spec/rwlock.h +++ b/include/odp/api/spec/rwlock.h @@ -25,7 +25,8 @@ extern "C" { * A reader/writer lock allows multiple simultaneous readers but only one * writer at a time. A thread that wants write access will have to wait until * there are no threads that want read access. This casues a risk for - * starvation. + * starvation. The trylock variants can be used to return an indication + * of whether the lock and access mode was immediately available. * @{ */ @@ -50,6 +51,16 @@ void odp_rwlock_init(odp_rwlock_t *rwlock); void odp_rwlock_read_lock(odp_rwlock_t *rwlock); /** + * Try to acquire read permission to a reader/writer lock. + * + * $param rwlock Pointer to a reader/writer lock + * + * @retval 0 Lock was not available for read access + * @retval 1 Read access to lock acquired + */ +int odp_rwlock_read_trylock(odp_rwlock_t *rwlock); + +/** * Release read permission on a reader/writer lock. * * @param rwlock Pointer to a reader/writer lock @@ -64,6 +75,16 @@ void odp_rwlock_read_unlock(odp_rwlock_t *rwlock); void odp_rwlock_write_lock(odp_rwlock_t *rwlock); /** + * Try to acquire write permisssion to a reader/writer lock. + * + * @param rwlock Pointer to a reader/writer lock + * + * @retval 0 Lock was not available for write access + * @retval 1 Write access to lock acquired + */ +int odp_rwlock_write_trylock(odp_rwlock_t *rwlock); + +/** * Release write permission on a reader/writer lock. * * @param rwlock Pointer to a reader/writer lock diff --git a/include/odp/api/spec/rwlock_recursive.h b/include/odp/api/spec/rwlock_recursive.h index 10b2f79..58d5e54 100644 --- a/include/odp/api/spec/rwlock_recursive.h +++ b/include/odp/api/spec/rwlock_recursive.h @@ -35,6 +35,9 @@ extern "C" { * * ... but this is not supported. * * read_lock(); write_lock(); write_unlock(); read_unlock(); + * + * The trylock variants can be used to return an indication of whether the + * lock and access mode was immediately available. * @{ */ @@ -62,6 +65,16 @@ void odp_rwlock_recursive_init(odp_rwlock_recursive_t *lock); void odp_rwlock_recursive_read_lock(odp_rwlock_recursive_t *lock); /** + * Try to acquire recursive rwlock for reading + * + * @param lock Pointer to a lock + * + * @retval 0 Lock was not available for read access + * @retval 1 Read access to lock acquired + */ +int odp_rwlock_recursive_read_trylock(odp_rwlock_recursive_t *lock); + +/** * Release recursive rwlock after reading * * @param lock Pointer to a lock @@ -80,6 +93,16 @@ void odp_rwlock_recursive_read_unlock(odp_rwlock_recursive_t *lock); void odp_rwlock_recursive_write_lock(odp_rwlock_recursive_t *lock); /** + * Try to acquire recursive rwlock for writing + * + * @param lock Pointer to a lock + * + * @retval 0 Lock was not available for write access + * @retval 1 Write access to lock acquired + */ +int odp_rwlock_recursive_write_trylock(odp_rwlock_recursive_t *lock); + +/** * Release recursive rwlock after writing * * @param lock Pointer to a lock