From 6a1b22578e95e76fceeb7fcd09aa2e86be9e60cf Mon Sep 17 00:00:00 2001 From: chyyuu Date: Mon, 1 Oct 2012 21:49:27 +0800 Subject: [PATCH] update atomic.h in lab6 --- code/lab6/libs/atomic.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/lab6/libs/atomic.h b/code/lab6/libs/atomic.h index 958be2e..e8f317b 100644 --- a/code/lab6/libs/atomic.h +++ b/code/lab6/libs/atomic.h @@ -53,5 +53,29 @@ test_bit(int nr, volatile void *addr) { return oldbit != 0; } +/* * + * test_and_set_bit - Atomically set a bit and return its old value + * @nr: the bit to set + * @addr: the address to count from + * */ +static inline bool +test_and_set_bit(int nr, volatile void *addr) { + int oldbit; + asm volatile ("btsl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory"); + return oldbit != 0; +} + +/* * + * test_and_clear_bit - Atomically clear a bit and return its old value + * @nr: the bit to clear + * @addr: the address to count from + * */ +static inline bool +test_and_clear_bit(int nr, volatile void *addr) { + int oldbit; + asm volatile ("btrl %2, %1; sbbl %0, %0" : "=r" (oldbit), "=m" (*(volatile long *)addr) : "Ir" (nr) : "memory"); + return oldbit != 0; +} + #endif /* !__LIBS_ATOMIC_H__ */