Skip to content
Snippets Groups Projects
Select Git revision
  • 8bc3bcc93a2b4e47d5d410146f6546bca6171663
  • vme-testing default
  • ci-test
  • master
  • remoteproc
  • am625-sk-ov5640
  • pcal6534-upstreaming
  • lps22df-upstreaming
  • msc-upstreaming
  • imx8mp
  • iio/noa1305
  • vme-next
  • vme-next-4.14-rc4
  • v4.14-rc4
  • v4.14-rc3
  • v4.14-rc2
  • v4.14-rc1
  • v4.13
  • vme-next-4.13-rc7
  • v4.13-rc7
  • v4.13-rc6
  • v4.13-rc5
  • v4.13-rc4
  • v4.13-rc3
  • v4.13-rc2
  • v4.13-rc1
  • v4.12
  • v4.12-rc7
  • v4.12-rc6
  • v4.12-rc5
  • v4.12-rc4
  • v4.12-rc3
32 results

dec_and_lock.c

Blame
  • dec_and_lock.c 784 B
    #include <linux/export.h>
    #include <linux/spinlock.h>
    #include <linux/atomic.h>
    
    /*
     * This is an implementation of the notion of "decrement a
     * reference count, and return locked if it decremented to zero".
     *
     * NOTE NOTE NOTE! This is _not_ equivalent to
     *
     *	if (atomic_dec_and_test(&atomic)) {
     *		spin_lock(&lock);
     *		return 1;
     *	}
     *	return 0;
     *
     * because the spin-lock and the decrement must be
     * "atomic".
     */
    int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
    {
    	/* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
    	if (atomic_add_unless(atomic, -1, 1))
    		return 0;
    
    	/* Otherwise do it the slow way */
    	spin_lock(lock);
    	if (atomic_dec_and_test(atomic))
    		return 1;
    	spin_unlock(lock);
    	return 0;
    }
    
    EXPORT_SYMBOL(_atomic_dec_and_lock);