Skip to content

Commit

Permalink
Add additional examples in Documentation/spinlocks.txt
Browse files Browse the repository at this point in the history
Checkpatch will throw an error if code doesn't use the correct initializers
for static spinlocks:

ERROR: Use of SPIN_LOCK_UNLOCKED is deprecated: see Documentation/spinlocks.txt

This is fine, but Documentation/spinlocks.txt isn't very clear on how to
_use_ the new initializers for static variables. To save people time in the
future, I added two small examples of how to fix old-style static
initializers to be more lockdep friendly.

Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
  • Loading branch information
Mark Fasheh authored and Jonathan Corbet committed Apr 11, 2008
1 parent d396c5f commit 14dadf1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Documentation/spinlocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ Please use DEFINE_SPINLOCK()/DEFINE_RWLOCK() or
__SPIN_LOCK_UNLOCKED()/__RW_LOCK_UNLOCKED() as appropriate for static
initialization.

Most of the time, you can simply turn:

static spinlock_t xxx_lock = SPIN_LOCK_UNLOCKED;

into:

static DEFINE_SPINLOCK(xxx_lock);

Static structure member variables go from:

struct foo bar {
.lock = SPIN_LOCK_UNLOCKED;
};

to:

struct foo bar {
.lock = __SPIN_LOCK_UNLOCKED(bar.lock);
};

Declaration of static rw_locks undergo a similar transformation.

Dynamic initialization, when necessary, may be performed as
demonstrated below.

Expand Down

0 comments on commit 14dadf1

Please sign in to comment.