From patchwork Mon May 30 17:27:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 830702 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4UHTG2R018765 for ; Mon, 30 May 2011 17:29:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757616Ab1E3R3W (ORCPT ); Mon, 30 May 2011 13:29:22 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:37171 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757501Ab1E3R3S (ORCPT ); Mon, 30 May 2011 13:29:18 -0400 Received: by wwk4 with SMTP id 4so1746243wwk.1 for ; Mon, 30 May 2011 10:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=tG/IXPcnZ0OQPiZn3MV5xSRLKT9m9raMFf2UtUk13HE=; b=QS+UHm4OPibofwuHPNNBPGcbnhdHSV8Z5q+yvEaUrQ9C+DGfMqZbicTRV1HpiVUQp6 sOHQ1BlwShXpFMS9k18g1k0sKM57l5B1hZSQYOOkFnHDr+BhF23imaFfKJGaNgH+t8QV QxyHz2Fmp2UuBZfS9sT4Afnj4NJvP49M2pVPc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=uiAL554UhQRv6CzWSsBN6/6XIBch1DKw4Z8POwbyxUaYudDtKzkbNnaBp/GkZZwC57 8soBZW0z9SUwyibqZ+lHN/5jDy+nLY85qjPPUe/J5DssRbjTRTQE9WXURMLCfsBg3zqT aBv4QsmPyxcuvKdwxgmh+Cew2nhtC8CrQsyzY= Received: by 10.227.11.67 with SMTP id s3mr5172965wbs.62.1306776557162; Mon, 30 May 2011 10:29:17 -0700 (PDT) Received: from localhost.localdomain (bzq-79-181-201-100.red.bezeqint.net [79.181.201.100]) by mx.google.com with ESMTPS id gb6sm3194848wbb.17.2011.05.30.10.29.15 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 May 2011 10:29:16 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH v3 6/8] kvm tools: Add rwlock wrapper Date: Mon, 30 May 2011 20:27:56 +0300 Message-Id: <1306776478-29613-7-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.3 In-Reply-To: <1306776478-29613-1-git-send-email-levinsasha928@gmail.com> References: <1306776478-29613-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 30 May 2011 17:29:49 +0000 (UTC) Adds a rwlock wrapper which like the mutex wrapper makes rwlock calls similar to their kernel counterparts. Signed-off-by: Sasha Levin --- tools/kvm/include/kvm/rwsem.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/include/kvm/rwsem.h diff --git a/tools/kvm/include/kvm/rwsem.h b/tools/kvm/include/kvm/rwsem.h new file mode 100644 index 0000000..75a22f8 --- /dev/null +++ b/tools/kvm/include/kvm/rwsem.h @@ -0,0 +1,39 @@ +#ifndef KVM__RWSEM_H +#define KVM__RWSEM_H + +#include + +#include "kvm/util.h" + +/* + * Kernel-alike rwsem API - to make it easier for kernel developers + * to write user-space code! :-) + */ + +#define DECLARE_RWSEM(sem) pthread_rwlock_t sem = PTHREAD_RWLOCK_INITIALIZER + +static inline void down_read(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_rdlock(rwsem) != 0) + die("unexpected pthread_rwlock_rdlock() failure!"); +} + +static inline void down_write(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_wrlock(rwsem) != 0) + die("unexpected pthread_rwlock_wrlock() failure!"); +} + +static inline void up_read(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_unlock(rwsem) != 0) + die("unexpected pthread_rwlock_unlock() failure!"); +} + +static inline void up_write(pthread_rwlock_t *rwsem) +{ + if (pthread_rwlock_unlock(rwsem) != 0) + die("unexpected pthread_rwlock_unlock() failure!"); +} + +#endif /* KVM__RWSEM_H */