UbixOS  2.0
spinlock.c File Reference
#include <sys/_null.h>
#include <ubixos/spinlock.h>
#include <ubixos/sched.h>
#include <string.h>
Include dependency graph for spinlock.c:

Go to the source code of this file.

Macros

#define atomic_add(P, V)   __sync_add_and_fetch((P), (V))
 
#define atomic_clear_bit(P, V)   __sync_and_and_fetch((P), ~(1<<(V)))
 
#define atomic_dec(P)   __sync_add_and_fetch((P), -1)
 
#define atomic_inc(P)   __sync_add_and_fetch((P), 1)
 
#define atomic_set_bit(P, V)   __sync_or_and_fetch((P), 1<<(V))
 
#define atomic_xadd(P, V)   __sync_fetch_and_add((P), (V))
 
#define barrier()   asm volatile("": : :"memory")
 
#define cmpxchg(P, O, N)   __sync_val_compare_and_swap((P), (O), (N))
 
#define cpu_relax()   asm volatile("pause\n": : :"memory")
 

Functions

void spinLock (spinLock_t lock)
 
void spinLockInit (spinLock_t lock)
 
int spinTryLock (spinLock_t lock)
 
void spinUnlock (spinLock_t lock)
 

Macro Definition Documentation

◆ atomic_add

#define atomic_add (   P,
 
)    __sync_add_and_fetch((P), (V))

Definition at line 38 of file spinlock.c.

◆ atomic_clear_bit

#define atomic_clear_bit (   P,
 
)    __sync_and_and_fetch((P), ~(1<<(V)))

Definition at line 40 of file spinlock.c.

◆ atomic_dec

#define atomic_dec (   P)    __sync_add_and_fetch((P), -1)

Definition at line 37 of file spinlock.c.

◆ atomic_inc

#define atomic_inc (   P)    __sync_add_and_fetch((P), 1)

Definition at line 36 of file spinlock.c.

◆ atomic_set_bit

#define atomic_set_bit (   P,
 
)    __sync_or_and_fetch((P), 1<<(V))

Definition at line 39 of file spinlock.c.

◆ atomic_xadd

#define atomic_xadd (   P,
 
)    __sync_fetch_and_add((P), (V))

Definition at line 34 of file spinlock.c.

◆ barrier

#define barrier ( )    asm volatile("": : :"memory")

Definition at line 42 of file spinlock.c.

◆ cmpxchg

#define cmpxchg (   P,
  O,
 
)    __sync_val_compare_and_swap((P), (O), (N))

Definition at line 35 of file spinlock.c.

◆ cpu_relax

#define cpu_relax ( )    asm volatile("pause\n": : :"memory")

Definition at line 45 of file spinlock.c.

Function Documentation

◆ spinLock()

void spinLock ( spinLock_t  lock)

Definition at line 64 of file spinlock.c.

◆ spinLockInit()

void spinLockInit ( spinLock_t  lock)

Definition at line 47 of file spinlock.c.

References memset().

Here is the call graph for this function:

◆ spinTryLock()

int spinTryLock ( spinLock_t  lock)

Definition at line 51 of file spinlock.c.

References cmpxchg, LLOCK_FLAG, LOCKED, spinLock::locked, and NULL.

◆ spinUnlock()

void spinUnlock ( spinLock_t  lock)

Definition at line 59 of file spinlock.c.

References barrier, and spinLock::locked.