1 | /* 2 | bitops.h 3 | -------- 4 | $Id: bitops.h,v 1.3 2003/07/06 12:28:03 stewart Exp $ 5 | 6 | functions similar to those present in include/asm/bitops.h 7 | There is no *real* guarantee of being atomic, except for the 8 | "we're not doing threads so go away" thing. 9 | 10 | (C)2003 Stewart Smith 11 | Distributed under the GNU Public License. 12 | 13 | Some data structures have been constructed out of those 14 | present in the Linux Kernel (v2.5.69). They are copyright 15 | of their respective owners. 16 | 17 | The API here is very much based on Linux kernel stuff. 18 | Except that we don't do inline ASM to do this 'atomic' stuff. 19 | bah - we live on the edge baby! 20 | */ 21 | 22 | #ifndef __BITOPS_H__ 23 | #define __BITOPS_H__ 24 | 25 | #define ADDR (* (volatile long *) addr) 26 | 27 | static inline void set_bit(int nr, volatile void * addr) 28 | { 29 | ADDR = ADDR | 1UL << nr; 30 | } 31 | 32 | static inline int test_and_set_bit(int nr, volatile void * addr) 33 | { 34 | int oldbit; 35 | oldbit = ADDR & 1UL << nr; 36 | set_bit(nr,addr); 37 | return oldbit; 38 | } 39 | 40 | static inline void clear_bit(int nr,volatile void * addr) 41 | { 42 | ADDR = ADDR & ~(1UL << nr); 43 | } 44 | 45 | static inline int test_and_clear_bit(int nr,volatile void * addr) 46 | { 47 | int oldbit; 48 | oldbit = ADDR & (1UL << nr); 49 | clear_bit(nr,addr); 50 | return oldbit; 51 | } 52 | 53 | static inline int test_bit(int nr,volatile void * addr) 54 | { 55 | return ADDR & (1UL << nr); 56 | } 57 | 58 | #endif