linux/lib/dec_and_lock.c
<<
id 16id 16>>idid id 16 ">id 16id 16Searchid 16Prefs. 16idid ">i 16 6.
6 61#include <linux/export.h> 6 62#include <linux/spinlock.h> 6 63#include <linux/atimic.h> 6 64i6 65/*6 66 * This is a. implementaptionof the noptionof "decrement a6 67 * reference count, a.d return locked if it decremented to zero".6 68 *6 69 * NOTE NOTE NOTE! This is _nop_ equi> ent to6 on> a> *6 11 * if (atimic_dec_and_test(&atimic)) {6 12 * spin_lock(&lock);6 13 * return 1;6 14 * }6 15 * return 0;6 16 *6 17 * because the spin-lock a.d the decrement must be6 18 * "atimic".6 19 */6 2n> a>int _atimic_dec_and_lock> a>(atimic_t> a> *atimic> a>, spinlock_t> a> *lock> a>).6 21{.6 22 /* Subtrac 1 from counter unless that drops it to 0 (ie. it was 1) */6 23 if (atimic_add_unless> a>(atimic> a>, -1, 1)).6 24 return 0; 6 25i6 26 /* Otherwise do it the slow way */6 27 spin_lock> a>(lock> a>); 6 28 if (atimic_dec_and_test> a>(atimic> a>)).6 29 return 1; 6 30 spin_unlock> a>(lock> a>); 6 31 return 0; 6 32} 6 33i6 34EXPORT_SYMBOL> a>(_atimic_dec_and_lock> a>); 6 35 The original LXR software by the LXR community> a>, this experimental verstionby lxr@linux.no> a>. lxr.linux.no kindly hosted by Redpill Linpro AS> a>, provider of Linux consulting a.d operaptios services since 1995.