kfifo: provide kfifo_is_empty_spinlocked()
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 17 Dec 2019 10:30:59 +0000 (11:30 +0100)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 12 Feb 2020 11:05:46 +0000 (12:05 +0100)
Provide two spinlocked versions of kfifo_is_empty() to be used with
spinlocked variants of kfifo_in() and kfifo_out().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Acked-by: Stefani Seibold <stefani@seibold.net>
include/linux/kfifo.h

index 123c200..8624947 100644 (file)
@@ -247,6 +247,37 @@ __kfifo_int_must_check_helper(int val)
 })
 
 /**
+ * kfifo_is_empty_spinlocked - returns true if the fifo is empty using
+ * a spinlock for locking
+ * @fifo: address of the fifo to be used
+ * @lock: spinlock to be used for locking
+ */
+#define kfifo_is_empty_spinlocked(fifo, lock) \
+({ \
+       unsigned long __flags; \
+       bool __ret; \
+       spin_lock_irqsave(lock, __flags); \
+       __ret = kfifo_is_empty(fifo); \
+       spin_unlock_irqrestore(lock, __flags); \
+       __ret; \
+})
+
+/**
+ * kfifo_is_empty_spinlocked_noirqsave  - returns true if the fifo is empty
+ * using a spinlock for locking, doesn't disable interrupts
+ * @fifo: address of the fifo to be used
+ * @lock: spinlock to be used for locking
+ */
+#define kfifo_is_empty_spinlocked_noirqsave(fifo, lock) \
+({ \
+       bool __ret; \
+       spin_lock(lock); \
+       __ret = kfifo_is_empty(fifo); \
+       spin_unlock(lock); \
+       __ret; \
+})
+
+/**
  * kfifo_is_full - returns true if the fifo is full
  * @fifo: address of the fifo to be used
  */