40 #ifndef DELAUNAY_SYNC_H
41 #define DELAUNAY_SYNC_H
50 #define GEO_CONNECTION_MACHINE
70 #ifdef GEO_CONNECTION_MACHINE
72 typedef uint16_t thread_index_t;
73 typedef uint16_t cell_status_t;
74 static constexpr cell_status_t FREE_CELL = 32767;
75 static constexpr cell_status_t THREAD_MASK = 32767;
76 static constexpr cell_status_t CONFLICT_MASK = 32768;
78 typedef uint8_t thread_index_t;
79 typedef uint8_t cell_status_t;
80 static constexpr cell_status_t FREE_CELL = 127;
81 static constexpr cell_status_t THREAD_MASK = 127;
82 static constexpr cell_status_t CONFLICT_MASK = 128;
98 cell_status_(nullptr), size_(0), capacity_(0) {
133 cell_status_t expected = FREE_CELL;
136 cell_status_[cell].compare_exchange_strong(
138 std::memory_order_acquire,std::memory_order_acquire
142 return (expected & THREAD_MASK);
152 cell_status_[cell].store(FREE_CELL, std::memory_order_release);
164 cell_status_[cell].load(std::memory_order_relaxed) &
180 cell_status_[cell].load(std::memory_order_relaxed) &
194 cell_status_[cell].fetch_or(
195 CONFLICT_MASK, std::memory_order_relaxed
207 cell_status_[cell].store(status, std::memory_order_relaxed);
220 if(capacity_in > capacity_) {
221 capacity_ = capacity_in;
222 std::atomic<cell_status_t>* old_cell_status = cell_status_;
223 cell_status_ =
new std::atomic<cell_status_t>[capacity_];
224 for(
index_t i=0; i<capacity_; ++i) {
225 cell_status_t val = (i < size_) ?
226 old_cell_status[i].load(std::memory_order_relaxed) :
228 std::atomic_init(&cell_status_[i],val);
230 delete[] old_cell_status;
233 #ifdef __cpp_lib_atomic_is_always_lock_free
234 static_assert(std::atomic<cell_status_t>::is_always_lock_free);
257 if(new_capacity > capacity_) {
258 resize(size_, new_capacity);
267 if(size_+1 >= capacity_) {
268 resize(size_+1, std::max(capacity_*2,size_+1));
270 resize(size_+1, capacity_);
290 for(
index_t i=0; i<size_; ++i) {
294 delete[] cell_status_;
300 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.