linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: icoolidge@google.com (Ian Coolidge)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm: spinlock: const qualify read-only functions.
Date: Thu, 29 Oct 2015 17:27:00 -0700	[thread overview]
Message-ID: <1446164820-16144-1-git-send-email-icoolidge@google.com> (raw)
In-Reply-To: <1446061495-38554-1-git-send-email-icoolidge@google.com>

This allows assert_spin_locked() to be used against
spinlocks that are const qualified.

For example:

struct instance_t {
	int data;
	spinlock_t lock;
};

/*
 * foo does not mutate instance.
 * foo must be called while the lock is held.
 */
int foo(const instance_t *instance) {
	assert_spin_locked(&instance->lock);

	/* Code that assumes the lock is held */

	return 0;
}

Signed-off-by: Ian Coolidge <icoolidge@google.com>
---
 arch/arm/include/asm/spinlock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
index 0fa4184..274ceb1 100644
--- a/arch/arm/include/asm/spinlock.h
+++ b/arch/arm/include/asm/spinlock.h
@@ -118,12 +118,12 @@ static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
 	return lock.tickets.owner == lock.tickets.next;
 }
 
-static inline int arch_spin_is_locked(arch_spinlock_t *lock)
+static inline int arch_spin_is_locked(const arch_spinlock_t *lock)
 {
 	return !arch_spin_value_unlocked(READ_ONCE(*lock));
 }
 
-static inline int arch_spin_is_contended(arch_spinlock_t *lock)
+static inline int arch_spin_is_contended(const arch_spinlock_t *lock)
 {
 	struct __raw_tickets tickets = READ_ONCE(lock->tickets);
 	return (tickets.next - tickets.owner) > 1;
-- 
2.6.0.rc2.230.g3dd15c0

  parent reply	other threads:[~2015-10-30  0:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-28 19:44 [PATCH] arm: spinlock: const qualify read-only functions Ian Coolidge
2015-10-28 19:44 ` [PATCH] arm64: " Ian Coolidge
2015-10-29 21:51 ` [PATCH] arm: " Arnd Bergmann
2015-10-30  0:27 ` Ian Coolidge [this message]
2015-10-31 17:26   ` Ian Coolidge
2015-10-31 18:34     ` Ard Biesheuvel
2015-10-31 19:46       ` Ian Coolidge
2015-10-31 19:49         ` Ian Coolidge
  -- strict thread matches above, loose matches on Subject: below --
2015-10-29  0:47 Ian Coolidge
2015-10-31 16:30 ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446164820-16144-1-git-send-email-icoolidge@google.com \
    --to=icoolidge@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).