From patchwork Sat Mar 5 20:10:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 63624 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp786630lbc; Sat, 5 Mar 2016 16:43:41 -0800 (PST) X-Received: by 10.140.93.166 with SMTP id d35mr19472045qge.29.1457225021534; Sat, 05 Mar 2016 16:43:41 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k9si10263873qge.20.2016.03.05.16.43.40; Sat, 05 Mar 2016 16:43:41 -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 815E061850; Sun, 6 Mar 2016 00:43:40 +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=-1.0 required=5.0 tests=BAYES_00, DATE_IN_PAST_03_06, 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 83668617FA; Sun, 6 Mar 2016 00:43:35 +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 0E1FB617FA; Sun, 6 Mar 2016 00:43:34 +0000 (UTC) Received: from mail-pf0-f174.google.com (mail-pf0-f174.google.com [209.85.192.174]) by lists.linaro.org (Postfix) with ESMTPS id 17823617DC for ; Sun, 6 Mar 2016 00:43:33 +0000 (UTC) Received: by mail-pf0-f174.google.com with SMTP id 129so13353136pfw.1 for ; Sat, 05 Mar 2016 16:43:33 -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=cCWQYFF22lsnglNXMU11WkMyR38SO5TvephF30yksFE=; b=UKFFOBzzo2NZ2lwcokflrrkPs5suwo4u8Tocw70wpICkirdPZgVixcOkkNow00d6qq oRTEGZ/gYNO3OOG/6u8H5t8knVfTdBAqEjn0nhkBSsvqVa5X5hQcU7FG+/4Djwr3XSQG ME6fWoLR1zBRq27hIys2REnMrJqxTpi1yfEufZurPMGjgHHet1SaC5ObG97V5eMG0Ul8 GU0nKN6ICcx4CeUb96KZUBIpNFehJMM7bdOrhGuU3fmb+H9o26rI2M8POv3tiJDTneds uVDKuf0nowi0kMvN+25QJl5P0aobZaY4P+DC931sGjCQchRq/d1wSoXRmstktS7NLEhU kDFQ== X-Gm-Message-State: AD7BkJIGWfSrP44stkX4U8Z6X3H6OzAsMwvip5+72QG3e8IoerRScfpYaSbiamkpoM2/yyIfU0Q= X-Received: by 10.98.10.204 with SMTP id 73mr23196285pfk.87.1457225012327; Sat, 05 Mar 2016 16:43:32 -0800 (PST) Received: from Ubuntu15.localdomain (110-170-137-3.static.asianet.co.th. [110.170.137.3]) by smtp.gmail.com with ESMTPSA id w20sm14775280pfi.31.2016.03.05.16.43.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 05 Mar 2016 16:43:31 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 6 Mar 2016 07:10:30 +1100 Message-Id: <1457208633-1453-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 1/4] 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 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..9ca8872 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 avoid blocking when + * the lock is not 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 !0 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 permission to a reader/writer lock. + * + * @param rwlock Pointer to a reader/writer lock + * + * @retval 0 Lock was not available for write access + * @retval !0 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..965fcc0 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 avoid blocking when the lock + * is not 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 !0 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 !0 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