Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
interlocked.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
11
#include "
core/types.h
"
12
13
//------------------------------------------------------------------------------
14
namespace
Gcc
15
{
16
class
GccInterlocked
17
{
18
public
:
20
static
int
Increment
(
int
volatile
* var);
22
static
int
Decrement
(
int
volatile
* var);
24
static
long
Increment
(
long
volatile
* var);
26
static
long
Decrement
(
long
volatile
* var);
28
static
int
Add
(
int
volatile
* var,
int
add);
30
static
int
Or
(
int
volatile
* var,
int
value);
32
static
int
And
(
int
volatile
* var,
int
value);
34
static
int
Xor
(
int
volatile
* var,
int
value);
36
static
int
Exchange
(
int
volatile
* dest,
int
value);
38
static
void
*
ExchangePointer
(
void
*
volatile
* dest,
void
* value);
40
static
int
CompareExchange
(
int
volatile
* dest,
int
exchange,
int
comparand);
42
static
void
*
CompareExchangePointer
(
void
*
volatile
* dest,
void
* exchange,
void
* comparand);
43
};
44
45
//------------------------------------------------------------------------------
48
inline
int
49
GccInterlocked::Increment
(
int
volatile
* var)
50
{
51
return
__sync_add_and_fetch(var, 1);
52
}
53
54
//------------------------------------------------------------------------------
57
inline
int
58
GccInterlocked::Decrement
(
int
volatile
* var)
59
{
60
return
__sync_sub_and_fetch(var, 1);
61
}
62
63
//------------------------------------------------------------------------------
66
inline
long
67
GccInterlocked::Increment
(
long
volatile
* var)
68
{
69
return
__sync_add_and_fetch(var, 1);
70
}
71
72
//------------------------------------------------------------------------------
75
inline
long
76
GccInterlocked::Decrement
(
long
volatile
* var)
77
{
78
return
__sync_sub_and_fetch(var, 1);
79
}
80
81
//------------------------------------------------------------------------------
84
inline
int
85
GccInterlocked::Add
(
int
volatile
* var,
int
add)
86
{
87
return
__sync_fetch_and_add(var, add);
88
}
89
90
//------------------------------------------------------------------------------
93
inline
int
94
GccInterlocked::Or
(
int
volatile
* var,
int
add)
95
{
96
return
__sync_fetch_and_or(var, add);
97
}
98
99
//------------------------------------------------------------------------------
102
inline
int
103
GccInterlocked::And
(
int
volatile
* var,
int
add)
104
{
105
return
__sync_fetch_and_and(var, add);
106
}
107
108
//------------------------------------------------------------------------------
111
inline
int
112
GccInterlocked::Xor
(
int
volatile
* var,
int
add)
113
{
114
return
__sync_fetch_and_xor(var, add);
115
}
116
117
//------------------------------------------------------------------------------
120
inline
int
121
GccInterlocked::Exchange
(
int
volatile
* dest,
int
value)
122
{
123
return
__sync_lock_test_and_set(dest, value);
124
}
125
126
//------------------------------------------------------------------------------
129
inline
void
*
130
GccInterlocked::ExchangePointer
(
void
*
volatile
* dest,
void
* value)
131
{
132
return
__sync_lock_test_and_set(dest, value);
133
}
134
135
//------------------------------------------------------------------------------
138
inline
int
139
GccInterlocked::CompareExchange
(
int
volatile
* dest,
int
exchange,
int
comparand)
140
{
141
return
__sync_val_compare_and_swap(dest, comparand, exchange);
142
}
143
144
//------------------------------------------------------------------------------
147
inline
void
*
148
GccInterlocked::CompareExchangePointer
(
void
*
volatile
* dest,
void
* exchange,
void
* comparand)
149
{
150
return
__sync_val_compare_and_swap(dest, comparand, exchange);
151
}
152
153
}
// namespace Gcc
154
//------------------------------------------------------------------------------
Gcc::GccInterlocked
Provides simple atomic operations on shared variables using gcc compiler builtins.
Definition
interlocked.h:17
Gcc::GccInterlocked::Xor
static int Xor(int volatile *var, int value)
interlocked xor
Definition
interlocked.h:112
Gcc::GccInterlocked::ExchangePointer
static void * ExchangePointer(void *volatile *dest, void *value)
interlocked exchange
Definition
interlocked.h:130
Gcc::GccInterlocked::Or
static int Or(int volatile *var, int value)
interlocked or
Definition
interlocked.h:94
Gcc::GccInterlocked::Decrement
static int Decrement(int volatile *var)
interlocked decrement
Definition
interlocked.h:58
Gcc::GccInterlocked::Add
static int Add(int volatile *var, int add)
interlocked add
Definition
interlocked.h:85
Gcc::GccInterlocked::CompareExchange
static int CompareExchange(int volatile *dest, int exchange, int comparand)
interlocked compare-exchange
Definition
interlocked.h:139
Gcc::GccInterlocked::And
static int And(int volatile *var, int value)
interlocked and
Definition
interlocked.h:103
Gcc::GccInterlocked::CompareExchangePointer
static void * CompareExchangePointer(void *volatile *dest, void *exchange, void *comparand)
interlocked exchange
Definition
interlocked.h:148
Gcc::GccInterlocked::Exchange
static int Exchange(int volatile *dest, int value)
interlocked exchange
Definition
interlocked.h:121
Gcc::GccInterlocked::Increment
static int Increment(int volatile *var)
interlocked increment
Definition
interlocked.h:49
Gcc
Definition
interlocked.h:15
types.h
code
foundation
threading
gcc
interlocked.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.