Commit b446406a authored by Nathan Bronson's avatar Nathan Bronson Committed by woo

add some missing methods to DeterministicAtomic

Summary:
fetch_and and fetch_or are actually required in some instances,
since the operation they perform isn't reversible.  This also adds some
other missing functions, ^= and fetch_{add,sub,xor}.

Test Plan: use from other code's unit tests

Reviewed By: mssarang@fb.com

Subscribers: yfeldblum, folly-diffs@

FB internal diff: D1798924

Signature: t1:1798924:1422892374:a9859039075ddcac54f75259b9bc6a29bb963a09
parent ba7fdc79
......@@ -248,6 +248,14 @@ struct DeterministicAtomic {
return rv;
}
T fetch_add(T v, std::memory_order mo = std::memory_order_seq_cst) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = data;
data += v;
DeterministicSchedule::afterSharedAccess();
return rv;
}
T operator-= (T v) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = (data -= v);
......@@ -255,6 +263,14 @@ struct DeterministicAtomic {
return rv;
}
T fetch_sub(T v, std::memory_order mo = std::memory_order_seq_cst) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = data;
data -= v;
DeterministicSchedule::afterSharedAccess();
return rv;
}
T operator&= (T v) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = (data &= v);
......@@ -262,12 +278,43 @@ struct DeterministicAtomic {
return rv;
}
T fetch_and(T v, std::memory_order mo = std::memory_order_seq_cst) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = data;
data &= v;
DeterministicSchedule::afterSharedAccess();
return rv;
}
T operator|= (T v) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = (data |= v);
DeterministicSchedule::afterSharedAccess();
return rv;
}
T fetch_or(T v, std::memory_order mo = std::memory_order_seq_cst) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = data;
data |= v;
DeterministicSchedule::afterSharedAccess();
return rv;
}
T operator^= (T v) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = (data ^= v);
DeterministicSchedule::afterSharedAccess();
return rv;
}
T fetch_xor(T v, std::memory_order mo = std::memory_order_seq_cst) noexcept {
DeterministicSchedule::beforeSharedAccess();
T rv = data;
data ^= v;
DeterministicSchedule::afterSharedAccess();
return rv;
}
};
}} // namespace folly::test
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment