MentOS  0.8.0
The Mentoring Operating System
Macros | Typedefs | Functions
stdatomic.h File Reference

Go to the source code of this file.

Macros

#define LOCK_PREFIX   "\n\tlock; "
 The prefix used to lock.
 
#define barrier()
 Compile read-write barrier. More...
 
#define cpu_relax()
 Pause instruction to prevent excess processor bus usage. More...
 

Typedefs

typedef volatile unsigned atomic_t
 Standard structure for atomic operations (see below for volatile explanation).
 

Functions

static int atomic_set_and_test (atomic_t *ptr, int value)
 Atomically sets value at ptr. More...
 
static void atomic_set (atomic_t *ptr, int value)
 Atomically set the value pointed by ptr to value. More...
 
static int atomic_read (const atomic_t *ptr)
 Atomically read the value pointed by ptr. More...
 
static int atomic_add (atomic_t *ptr, int value)
 Atomically add value to the value pointed by ptr. More...
 
static int atomic_sub (atomic_t *ptr, int value)
 Atomically subtract value from the value pointed by ptr. More...
 
static int atomic_inc (atomic_t *ptr)
 Atomically increment the value at ptr. More...
 
static int atomic_dec (atomic_t *ptr)
 Atomically decrement the value at ptr. More...
 
static int atomic_add_negative (atomic_t *ptr, int value)
 Atomically add value to ptr and checks if the result is negative. More...
 
static int atomic_sub_and_test (atomic_t *ptr, int value)
 Atomically subtract value from ptr and checks if the result is zero. More...
 
static int atomic_inc_and_test (atomic_t *ptr)
 Atomically increment ptr and checks if the result is zero. More...
 
static int atomic_dec_and_test (atomic_t *ptr)
 Atomically decrement ptr and checks if the result is zero. More...
 
static void set_bit (int offset, volatile unsigned long *base)
 Atomically sets a bit in memory, using Bit Test And Set (bts). More...
 
static void clear_bit (int offset, volatile unsigned long *base)
 Atomically clears a bit in memory. More...
 
static int test_bit (int offset, volatile unsigned long *base)
 Atomically tests a bit in memory. More...
 

Detailed Description

Macro Definition Documentation

◆ barrier

#define barrier ( )
Value:
__asm__ __volatile__("" \
: \
: \
: "memory")

Compile read-write barrier.

◆ cpu_relax

#define cpu_relax ( )
Value:
__asm__ __volatile__("pause\n" \
: \
: \
: "memory")

Pause instruction to prevent excess processor bus usage.

Function Documentation

◆ atomic_add()

static int atomic_add ( atomic_t ptr,
int  value 
)
inlinestatic

Atomically add value to the value pointed by ptr.

Parameters
ptrthe pointer we are working with.
valuethe value we need to add.
Returns
the result of the operation.

◆ atomic_add_negative()

static int atomic_add_negative ( atomic_t ptr,
int  value 
)
inlinestatic

Atomically add value to ptr and checks if the result is negative.

Parameters
ptrthe pointer we are working with.
valuethe value we need to add.
Returns
true if the result is negative, false otherwise.

◆ atomic_dec()

static int atomic_dec ( atomic_t ptr)
inlinestatic

Atomically decrement the value at ptr.

Parameters
ptrthe pointer we are working with.
Returns
the result of the operation.

◆ atomic_dec_and_test()

static int atomic_dec_and_test ( atomic_t ptr)
inlinestatic

Atomically decrement ptr and checks if the result is zero.

Parameters
ptrthe pointer we are working with.
Returns
true if the result is zero, false otherwise.

◆ atomic_inc()

static int atomic_inc ( atomic_t ptr)
inlinestatic

Atomically increment the value at ptr.

Parameters
ptrthe pointer we are working with.
Returns
the result of the operation.

◆ atomic_inc_and_test()

static int atomic_inc_and_test ( atomic_t ptr)
inlinestatic

Atomically increment ptr and checks if the result is zero.

Parameters
ptrthe pointer we are working with.
Returns
true if the result is zero, false otherwise.

◆ atomic_read()

static int atomic_read ( const atomic_t ptr)
inlinestatic

Atomically read the value pointed by ptr.

Parameters
ptrthe pointer we are working with.
Returns
the value we read.

◆ atomic_set()

static void atomic_set ( atomic_t ptr,
int  value 
)
inlinestatic

Atomically set the value pointed by ptr to value.

Parameters
ptrthe pointer we are working with.
valuethe value we need to set.

◆ atomic_set_and_test()

static int atomic_set_and_test ( atomic_t ptr,
int  value 
)
inlinestatic

Atomically sets value at ptr.

Parameters
ptrthe pointer we are working with.
valuethe value to set.
Returns
The final value of the atomic variable.

◆ atomic_sub()

static int atomic_sub ( atomic_t ptr,
int  value 
)
inlinestatic

Atomically subtract value from the value pointed by ptr.

Parameters
ptrthe pointer we are working with.
valuethe value we need to subtract.
Returns
the result of the operation.

◆ atomic_sub_and_test()

static int atomic_sub_and_test ( atomic_t ptr,
int  value 
)
inlinestatic

Atomically subtract value from ptr and checks if the result is zero.

Parameters
ptrthe pointer we are working with.
valuethe value we need to subtract.
Returns
true if the result is zero, false otherwise.

◆ clear_bit()

static void clear_bit ( int  offset,
volatile unsigned long *  base 
)
inlinestatic

Atomically clears a bit in memory.

Parameters
offsetThe offset to the bit.
baseThe base address.

◆ set_bit()

static void set_bit ( int  offset,
volatile unsigned long *  base 
)
inlinestatic

Atomically sets a bit in memory, using Bit Test And Set (bts).

Parameters
offsetThe offset to the bit.
baseThe base address.

◆ test_bit()

static int test_bit ( int  offset,
volatile unsigned long *  base 
)
inlinestatic

Atomically tests a bit in memory.

Parameters
offsetThe offset to the bit.
baseThe base address.
Returns
1 if the bit is set, 0 otherwise.