root/Whitix/trunk/include/locks.h

Revision 1995, 1.0 KB (checked in by mwhitworth, 3 years ago)

Add BitTestAndClear function.

Line 
1#ifndef LOCKS_H
2#define LOCKS_H
3
4#ifndef SMP
5#define PREFIX_LOCK             "lock; "
6#else
7#define PREFIX_LOCK     ""
8#endif
9
10#define ADDR (*(volatile long*)address)
11
12static inline int BitTest(volatile void* address, int bit)
13{
14        int oldBit;
15
16        asm volatile(""
17                "btl %2, %1\n\t"
18                "sbbl %0, %0"
19                : "=r"(oldBit)
20                : "m"(ADDR), "Ir"(bit));
21
22        return oldBit;
23}
24
25static inline void BitSet(volatile void* address, int bit)
26{
27        asm volatile(""
28                "btsl %1, %0"
29                :"+m"(ADDR)
30                :"Ir"(bit));
31}
32
33static inline void BitClear(volatile void* address, int bit)
34{
35        asm volatile(""
36                "btrl %1, %0"
37                :"+m"(ADDR)
38                :"Ir"(bit));
39}
40
41static inline int BitTestAndSet(volatile void* address, int bit)
42{
43        int oldBit;
44
45        asm volatile(""
46                "btsl %2, %1\n\t"
47                "sbbl %0, %0"
48                :"=r"(oldBit), "=m"(ADDR)
49                :"ir"(bit) : "memory");
50
51        return oldBit;
52}
53
54static inline int BitTestAndClear(volatile void* address, int bit)
55{
56        int oldBit;
57       
58        asm volatile(""
59                "btr %2, %1\n\t"
60                "sbb %0, %0"
61                : "=r"(oldBit), "=m"(ADDR)
62                : "Ir"(bit) : "memory");
63               
64        return oldBit;
65}
66
67#endif
Note: See TracBrowser for help on using the browser.