summaryrefslogtreecommitdiffstats
path: root/regressions/ck_spinlock/linux_spinlock.h
blob: 5fe1f3e21ef72805c331a64a28ad3311d2455870 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <ck_cc.h>

CK_CC_INLINE static void
spin_lock(volatile unsigned int *lock)
{
#ifdef __x86_64__
            __asm__ __volatile__(
                    "\n1:\t"
                    "lock ; decl %0\n\t"
                    "jns 2f\n"
                    "3:\n"
                    "rep;nop\n\t"
                    "cmpl $0,%0\n\t"
                    "jle 3b\n\t"
                    "jmp 1b\n"
                    "2:\t" : "=m" (*lock) : : "memory");
#else
	*lock = 1;
#endif

          return;
}

CK_CC_INLINE static void
spin_unlock(volatile unsigned int *lock)
{
#ifdef __x86_64__
        __asm__ __volatile__("movl $1,%0" :"=m" (*lock) :: "memory");
#else
	*lock = 0;
        return;
#endif
}

#define LOCK_NAME "linux_spinlock"
#define LOCK_DEFINE volatile unsigned int lock = 1
#define LOCK spin_lock(&lock)
#define UNLOCK spin_unlock(&lock)