Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
jshun committed Feb 22, 2015
1 parent 4ce329b commit ec90af6
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,12 @@ namespace sequence {
// this should work with pointer types, or pairs of integers
template <class ET>
inline bool CAS(ET *ptr, ET oldv, ET newv) {
if (sizeof(ET) == 8) {
long* o = (long*) &oldv;
long* n = (long*) &newv;
return __sync_bool_compare_and_swap((long*)ptr, *o, *n);
} else if (sizeof(ET) == 4) {
int* o = (int*) &oldv;
int* n = (int*) &newv;
return __sync_bool_compare_and_swap((int*)ptr, *o, *n);
} else {
if (sizeof(ET) == 4) {
return __sync_bool_compare_and_swap((int*)ptr, *((int*)&oldv), *((int*)&newv));
} else if (sizeof(ET) == 8) {
return __sync_bool_compare_and_swap((long*)ptr, *((long*)&oldv), *((long*)&newv));
}
else {
std::cout << "CAS bad length" << std::endl;
abort();
}
Expand Down

0 comments on commit ec90af6

Please sign in to comment.