35 36 inline void BitMap::verify_range(idx_t beg_index, idx_t end_index) const { 37 assert(beg_index <= end_index, "BitMap range error"); 38 // Note that [0,0) and [size,size) are both valid ranges. 39 if (end_index != _size) verify_index(end_index); 40 } 41 #endif // #ifdef ASSERT 42 43 inline void BitMap::set_bit(idx_t bit) { 44 verify_index(bit); 45 *word_addr(bit) |= bit_mask(bit); 46 } 47 48 inline void BitMap::clear_bit(idx_t bit) { 49 verify_index(bit); 50 *word_addr(bit) &= ~bit_mask(bit); 51 } 52 53 inline bool BitMap::par_set_bit(idx_t bit) { 54 verify_index(bit); 55 volatile idx_t* const addr = word_addr(bit); 56 const idx_t mask = bit_mask(bit); 57 idx_t old_val = *addr; 58 59 do { 60 const idx_t new_val = old_val | mask; 61 if (new_val == old_val) { 62 return false; // Someone else beat us to it. 63 } 64 const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val, 65 (volatile void*) addr, 66 (void*) old_val); 67 if (cur_val == old_val) { 68 return true; // Success. 69 } 70 old_val = cur_val; // The value changed, try again. 71 } while (true); 72 } 73 74 inline bool BitMap::par_clear_bit(idx_t bit) { 75 verify_index(bit); 76 volatile idx_t* const addr = word_addr(bit); 77 const idx_t mask = ~bit_mask(bit); 78 idx_t old_val = *addr; 79 80 do { 81 const idx_t new_val = old_val & mask; 82 if (new_val == old_val) { 83 return false; // Someone else beat us to it. 84 } 85 const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val, 86 (volatile void*) addr, 87 (void*) old_val); 88 if (cur_val == old_val) { 89 return true; // Success. 90 } 91 old_val = cur_val; // The value changed, try again. 92 } while (true); 93 } 94 95 inline void BitMap::set_range(idx_t beg, idx_t end, RangeSizeHint hint) { 96 if (hint == small_range && end - beg == 1) { 97 set_bit(beg); 98 } else { 99 if (hint == large_range) { 100 set_large_range(beg, end); 101 } else { 102 set_range(beg, end); 103 } 104 } 105 } | 35 36 inline void BitMap::verify_range(idx_t beg_index, idx_t end_index) const { 37 assert(beg_index <= end_index, "BitMap range error"); 38 // Note that [0,0) and [size,size) are both valid ranges. 39 if (end_index != _size) verify_index(end_index); 40 } 41 #endif // #ifdef ASSERT 42 43 inline void BitMap::set_bit(idx_t bit) { 44 verify_index(bit); 45 *word_addr(bit) |= bit_mask(bit); 46 } 47 48 inline void BitMap::clear_bit(idx_t bit) { 49 verify_index(bit); 50 *word_addr(bit) &= ~bit_mask(bit); 51 } 52 53 inline bool BitMap::par_set_bit(idx_t bit) { 54 verify_index(bit); 55 volatile bm_word_t* const addr = word_addr(bit); 56 const bm_word_t mask = bit_mask(bit); 57 bm_word_t old_val = *addr; 58 59 do { 60 const bm_word_t new_val = old_val | mask; 61 if (new_val == old_val) { 62 return false; // Someone else beat us to it. 63 } 64 const bm_word_t cur_val = (bm_word_t) Atomic::cmpxchg_ptr((void*) new_val, 65 (volatile void*) addr, 66 (void*) old_val); 67 if (cur_val == old_val) { 68 return true; // Success. 69 } 70 old_val = cur_val; // The value changed, try again. 71 } while (true); 72 } 73 74 inline bool BitMap::par_clear_bit(idx_t bit) { 75 verify_index(bit); 76 volatile bm_word_t* const addr = word_addr(bit); 77 const bm_word_t mask = ~bit_mask(bit); 78 bm_word_t old_val = *addr; 79 80 do { 81 const bm_word_t new_val = old_val & mask; 82 if (new_val == old_val) { 83 return false; // Someone else beat us to it. 84 } 85 const bm_word_t cur_val = (bm_word_t) Atomic::cmpxchg_ptr((void*) new_val, 86 (volatile void*) addr, 87 (void*) old_val); 88 if (cur_val == old_val) { 89 return true; // Success. 90 } 91 old_val = cur_val; // The value changed, try again. 92 } while (true); 93 } 94 95 inline void BitMap::set_range(idx_t beg, idx_t end, RangeSizeHint hint) { 96 if (hint == small_range && end - beg == 1) { 97 set_bit(beg); 98 } else { 99 if (hint == large_range) { 100 set_large_range(beg, end); 101 } else { 102 set_range(beg, end); 103 } 104 } 105 } |