-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtm_cas.h
More file actions
34 lines (31 loc) · 818 Bytes
/
htm_cas.h
File metadata and controls
34 lines (31 loc) · 818 Bytes
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
#include <immintrin.h>
#include <cstring>
typedef unsigned int u_int;
template <class T>
inline bool htm_compare_and_swap(T* obj, T* expected, T desired) {
unsigned status;
if (status = _xbegin() == _XBEGIN_STARTED) {
if (std::memcmp(obj, expected, sizeof(T)) == 0) {
std::memcpy(obj, &desired, sizeof(T));
_xend();
return true;
} else {
_xend();
}
}
return false;
}
template<>
inline bool htm_compare_and_swap<u_int>(u_int* obj, u_int* expected, u_int desired) {
unsigned status;
if (status = _xbegin() == _XBEGIN_STARTED) {
if (*obj == *expected) {
*obj = desired;
_xend();
return true;
} else {
_xend();
}
}
return false;
}