LWN.net Logo

Unified spinlock initialization

There have traditionally been two ways to initialize a spinlock inside the kernel. It can be done with an explicit assignment:

	spinlock_t lock = SPIN_LOCK_UNLOCKED;

or with a function call:

  	spinlock_t lock;
	spin_lock_init(&lock);

Linus has recently merged a set of patches which move all in-kernel initializations over to the function-based form. There has been no patch to remove the SPIN_LOCK_UNLOCKED macro, but it is not hard to see a move in that direction once the conversion is complete.

The stated reasons for this change include consistency and making life easier for automatic lock validators. There is also an unstated, but evident reason: the assignment form of lock initialization gets in the way of the realtime preemption patches. Those patches change most spinlocks in the kernel to a different, mutex type, and that breaks the initializers. As a result, the preemption patches must change all of those initializations throughout the kernel. By putting those specific changes into the mainline, it is possible to make the realtime patches smaller, less intrusive, and a little bit less scary.


(Log in to post comments)

Unified spinlock initialization

Posted Jan 13, 2010 5:28 UTC (Wed) by brandytea (guest, #62934) [Link]

Dear Sir:
I'm interested in your project, and wanna take part in it. But I'm not quite understand what "function-based form" means. And I recognized this project was established in 2004, is it time-out already?

Copyright © 2004, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds