40 #ifndef DELAUNAY_SYNC_H
41 #define DELAUNAY_SYNC_H
64 typedef uint8_t cell_status_t;
65 static constexpr cell_status_t FREE_CELL = 127;
66 static constexpr cell_status_t THREAD_MASK = 127;
67 static constexpr cell_status_t CONFLICT_MASK = 128;
80 cell_status_(nullptr), size_(0), capacity_(0) {
115 cell_status_t expected = FREE_CELL;
118 cell_status_[cell].compare_exchange_strong(
120 std::memory_order_acquire,std::memory_order_acquire
124 return (expected & THREAD_MASK);
134 cell_status_[cell].store(FREE_CELL, std::memory_order_release);
146 cell_status_[cell].load(std::memory_order_relaxed) &
162 cell_status_[cell].load(std::memory_order_relaxed) &
179 cell_status_[cell].store(
180 cell_status_[cell].load(
181 std::memory_order_relaxed
182 ) | CONFLICT_MASK, std::memory_order_relaxed
194 cell_status_[cell].store(status, std::memory_order_relaxed);
207 if(capacity_in > capacity_) {
208 capacity_ = capacity_in;
209 std::atomic<cell_status_t>* old_cell_status = cell_status_;
210 cell_status_ =
new std::atomic<cell_status_t>[capacity_];
211 for(
index_t i=0; i<capacity_; ++i) {
212 cell_status_t val = (i < size_) ?
213 old_cell_status[i].load(std::memory_order_relaxed) :
215 std::atomic_init(&cell_status_[i],val);
217 delete[] old_cell_status;
220 #ifdef __cpp_lib_atomic_is_always_lock_free
221 static_assert(std::atomic<cell_status_t>::is_always_lock_free);
244 if(new_capacity > capacity_) {
245 resize(size_, new_capacity);
254 if(size_+1 >= capacity_) {
255 resize(size_+1, std::max(capacity_*2,size_+1));
257 resize(size_+1, capacity_);
277 for(
index_t i=0; i<size_; ++i) {
281 delete[] cell_status_;
287 std::atomic<cell_status_t>* cell_status_;
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
An array of cell status codes associates to each tetrahedron in a Delaunay tetrahedralization.
void resize(index_t size_in)
Resizes this CellStatusArray.
void reserve(index_t new_capacity)
Reserves additional space.
void grow()
Increases the size of the array for one additional element.
CellStatusArray(index_t size_in)
Creates a CellStatusArray.
CellStatusArray(const CellStatusArray &rhs)=delete
Forbids copy.
void mark_cell_as_conflict(index_t cell)
Marks a cell as conflict.
CellStatusArray()
Creates an empty CellStatusArray.
void release_cell(index_t cell)
Releases a cell.
void resize(index_t size_in, index_t capacity_in)
Resizes this CellStatusArray.
void clear()
Clears this CellStatusArray.
bool cell_is_marked_as_conflict(index_t cell) const
Tests whether a cell is marked as conflict.
~CellStatusArray()
CellStatusArray destructor.
CellStatusArray & operator=(const CellStatusArray &rhs)=delete
Forbids copy.
void set_cell_status(index_t cell, cell_status_t status)
Sets the status of a cell.
index_t size() const
Gets the size of this CellStatusArray.
cell_status_t cell_thread(index_t cell) const
Gets the thread that acquired a cell.
cell_status_t acquire_cell(index_t cell, cell_status_t status)
Tentatively acquires a cell.
Common include file, providing basic definitions. Should be included before anything else by all head...
bool is_running_threads()
Checks whether threads are running.
Global Vorpaline namespace.
geo_index_t index_t
The type for storing and manipulating indices.