Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
c60095a8
Commit
c60095a8
authored
Dec 07, 2017
by
Sergey Vojtovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Faster atomic loads and stores on windows
parent
b04f2a0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
6 deletions
+37
-6
include/atomic/generic-msvc.h
include/atomic/generic-msvc.h
+37
-6
No files found.
include/atomic/generic-msvc.h
View file @
c60095a8
...
...
@@ -61,19 +61,43 @@ static inline int64 my_atomic_add64(int64 volatile *a, int64 v)
return
(
int64
)
InterlockedExchangeAdd64
((
volatile
LONGLONG
*
)
a
,
(
LONGLONG
)
v
);
}
/*
According to MSDN:
Simple reads and writes to properly-aligned 32-bit variables are atomic
operations.
...
Simple reads and writes to properly aligned 64-bit variables are atomic on
64-bit Windows. Reads and writes to 64-bit values are not guaranteed to be
atomic on 32-bit Windows.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684122(v=vs.85).aspx
*/
static
inline
int32
my_atomic_load32
(
int32
volatile
*
a
)
{
return
(
int32
)
InterlockedCompareExchange
((
volatile
LONG
*
)
a
,
0
,
0
);
int32
value
=
*
a
;
MemoryBarrier
();
return
value
;
}
static
inline
int64
my_atomic_load64
(
int64
volatile
*
a
)
{
return
(
int64
)
InterlockedCompareExchange64
((
volatile
LONGLONG
*
)
a
,
0
,
0
);
#ifdef _M_X64
int64
value
=
*
a
;
MemoryBarrier
();
return
value
;
#else
return
(
int64
)
InterlockedCompareExchange64
((
volatile
LONGLONG
*
)
a
,
0
,
0
);
#endif
}
static
inline
void
*
my_atomic_loadptr
(
void
*
volatile
*
a
)
{
return
InterlockedCompareExchangePointer
(
a
,
0
,
0
);
void
*
value
=
*
a
;
MemoryBarrier
();
return
value
;
}
static
inline
int32
my_atomic_fas32
(
int32
volatile
*
a
,
int32
v
)
...
...
@@ -93,17 +117,24 @@ static inline void * my_atomic_fasptr(void * volatile *a, void * v)
static
inline
void
my_atomic_store32
(
int32
volatile
*
a
,
int32
v
)
{
(
void
)
InterlockedExchange
((
volatile
LONG
*
)
a
,
v
);
MemoryBarrier
();
*
a
=
v
;
}
static
inline
void
my_atomic_store64
(
int64
volatile
*
a
,
int64
v
)
{
(
void
)
InterlockedExchange64
((
volatile
LONGLONG
*
)
a
,
v
);
#ifdef _M_X64
MemoryBarrier
();
*
a
=
v
;
#else
(
void
)
InterlockedExchange64
((
volatile
LONGLONG
*
)
a
,
v
);
#endif
}
static
inline
void
my_atomic_storeptr
(
void
*
volatile
*
a
,
void
*
v
)
{
(
void
)
InterlockedExchangePointer
(
a
,
v
);
MemoryBarrier
();
*
a
=
v
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment