Messages in this thread | | | Date | Wed, 9 Jul 2008 13:05:04 -0700 | From | Arjan van de Ven <> | Subject | Re: semaphore: lockless fastpath using atomic_{inc,dec}_return |
| |
> > > From your words if we do: > > spin_lock() > val = --foo; > spin_unlock(); > > Has the same cost than: > > val = atomic_dec_return(&foo);
yes
> How come I have the same number of atomic ops? > > Let's consider the fast case scenario (semaphore is unlocked for the > 'down' and has no waiters for 'up') in x86: > - with the spinlock only approach we have 2 atomic ops, xadd for > lock, inc for unlock. The unlock doesn't come for free in x86 after > all.
the unlock does not use an atomic operation.
-- If you want to reach me at my work email, use arjan@linux.intel.com For development, discussion and tips for power savings, visit http://www.lesswatts.org
| |