summaryrefslogtreecommitdiff
path: root/packed_array.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'packed_array.hpp')
-rw-r--r--packed_array.hpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/packed_array.hpp b/packed_array.hpp
index 9fb2c59..f4fa041 100644
--- a/packed_array.hpp
+++ b/packed_array.hpp
@@ -18,9 +18,12 @@ struct packed_array {
element(word_t *base, uint shift) : base(base), shift(shift) {}
T operator= (T val) {
- word_t mask = ~(((((word_t) 1) << bit_sz) - 1) << shift);
- *base &= mask;
- *base ^= val << shift;
+ word_t old_val, new_val;
+ do {
+ word_t mask = ~(((((word_t) 1) << bit_sz) - 1) << shift);
+ old_val = *((volatile word_t*) base);
+ new_val = (old_val & mask) ^ (val << shift);
+ } while (!__sync_bool_compare_and_swap(base, old_val, new_val));
return val;
}
contact: Jan Huwald // Impressum