~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/lib/dec_and_lock.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <linux/spinlock.h>
  2 #include <asm/atomic.h>
  3 
  4 /*
  5  * This is an architecture-neutral, but slow,
  6  * implementation of the notion of "decrement
  7  * a reference count, and return locked if it
  8  * decremented to zero".
  9  *
 10  * NOTE NOTE NOTE! This is _not_ equivalent to
 11  *
 12  *      if (atomic_dec_and_test(&atomic)) {
 13  *              spin_lock(&lock);
 14  *              return 1;
 15  *      }
 16  *      return 0;
 17  *
 18  * because the spin-lock and the decrement must be
 19  * "atomic".
 20  *
 21  * This slow version gets the spinlock unconditionally,
 22  * and releases it if it isn't needed. Architectures
 23  * are encouraged to come up with better approaches,
 24  * this is trivially done efficiently using a load-locked
 25  * store-conditional approach, for example.
 26  */
 27 
 28 #ifndef atomic_dec_and_lock
 29 int atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
 30 {
 31         spin_lock(lock);
 32         if (atomic_dec_and_test(atomic))
 33                 return 1;
 34         spin_unlock(lock);
 35         return 0;
 36 }
 37 #endif
 38 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.