#define localtry_lock_irqsave(lock, flags) \
__localtry_lock_irqsave(lock, flags)
+/**
+ * localtry_trylock - Try to acquire a per CPU local lock.
+ * @lock: The lock variable
+ *
+ * The function can be used in any context such as NMI or HARDIRQ. Due to
+ * locking constrains it will _always_ fail to acquire the lock in NMI or
+ * HARDIRQ context on PREEMPT_RT.
+ */
+#define localtry_trylock(lock) __localtry_trylock(lock)
+
/**
* localtry_trylock_irqsave - Try to acquire a per CPU local lock, save and disable
* interrupts if acquired
* @flags: Storage for interrupt flags
*
* The function can be used in any context such as NMI or HARDIRQ. Due to
- * locking constrains it will _always_ fail to acquire the lock on PREEMPT_RT.
+ * locking constrains it will _always_ fail to acquire the lock in NMI or
+ * HARDIRQ context on PREEMPT_RT.
*/
#define localtry_trylock_irqsave(lock, flags) \
__localtry_trylock_irqsave(lock, flags)
#define __localtry_lock_init(lock) \
do { \
__local_lock_init(&(lock)->llock); \
- WRITE_ONCE(&(lock)->acquired, 0); \
+ WRITE_ONCE((lock)->acquired, 0); \
} while (0)
#define __localtry_lock(lock) \
WRITE_ONCE(lt->acquired, 1); \
} while (0)
+#define __localtry_trylock(lock) \
+ ({ \
+ localtry_lock_t *lt; \
+ bool _ret; \
+ \
+ preempt_disable(); \
+ lt = this_cpu_ptr(lock); \
+ if (!READ_ONCE(lt->acquired)) { \
+ WRITE_ONCE(lt->acquired, 1); \
+ local_trylock_acquire(<->llock); \
+ _ret = true; \
+ } else { \
+ _ret = false; \
+ preempt_enable(); \
+ } \
+ _ret; \
+ })
+
#define __localtry_trylock_irqsave(lock, flags) \
({ \
localtry_lock_t *lt; \
#define __localtry_unlock_irq(lock) __local_unlock(lock)
#define __localtry_unlock_irqrestore(lock, flags) __local_unlock_irqrestore(lock, flags)
-#define __localtry_trylock_irqsave(lock, flags) \
+#define __localtry_trylock(lock) \
({ \
int __locked; \
\
- typecheck(unsigned long, flags); \
- flags = 0; \
if (in_nmi() | in_hardirq()) { \
__locked = 0; \
} else { \
__locked; \
})
+#define __localtry_trylock_irqsave(lock, flags) \
+ ({ \
+ typecheck(unsigned long, flags); \
+ flags = 0; \
+ __localtry_trylock(lock); \
+ })
+
#endif /* CONFIG_PREEMPT_RT */