mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Minor clean up
This commit is contained in:
@@ -1158,8 +1158,6 @@ gb_internal void init_checker_info(CheckerInfo *i) {
|
|||||||
string_map_init(&i->load_file_cache);
|
string_map_init(&i->load_file_cache);
|
||||||
array_init(&i->all_procedures, heap_allocator());
|
array_init(&i->all_procedures, heap_allocator());
|
||||||
|
|
||||||
TIME_SECTION("checker info: mpmc queues");
|
|
||||||
|
|
||||||
mpsc_init(&i->entity_queue, a); // 1<<20);
|
mpsc_init(&i->entity_queue, a); // 1<<20);
|
||||||
mpsc_init(&i->definition_queue, a); //); // 1<<20);
|
mpsc_init(&i->definition_queue, a); //); // 1<<20);
|
||||||
mpsc_init(&i->required_global_variable_queue, a); // 1<<10);
|
mpsc_init(&i->required_global_variable_queue, a); // 1<<10);
|
||||||
@@ -1711,7 +1709,6 @@ gb_internal void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, En
|
|||||||
|
|
||||||
is_lazy = (e->flags & EntityFlag_Lazy) == EntityFlag_Lazy;
|
is_lazy = (e->flags & EntityFlag_Lazy) == EntityFlag_Lazy;
|
||||||
if (!is_lazy) {
|
if (!is_lazy) {
|
||||||
GB_ASSERT(e != nullptr);
|
|
||||||
queue_count = mpsc_enqueue(&info->entity_queue, e);
|
queue_count = mpsc_enqueue(&info->entity_queue, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-17
@@ -11,37 +11,32 @@ struct MPSCNode {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct MPSCQueue {
|
struct MPSCQueue {
|
||||||
gbAllocator allocator;
|
gbAllocator allocator;
|
||||||
std::atomic<isize> count;
|
|
||||||
|
|
||||||
|
MPSCNode<T> sentinel;
|
||||||
std::atomic<MPSCNode<T> *> head;
|
std::atomic<MPSCNode<T> *> head;
|
||||||
std::atomic<MPSCNode<T> *> tail;
|
std::atomic<MPSCNode<T> *> tail;
|
||||||
MPSCNode<T> sentinel;
|
std::atomic<isize> count;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> gb_internal void mpsc_init (MPSCQueue<T> *q, gbAllocator const &allocator);
|
template <typename T> gb_internal void mpsc_init (MPSCQueue<T> *q, gbAllocator const &allocator);
|
||||||
template <typename T> gb_internal void mpsc_destroy(MPSCQueue<T> *q);
|
template <typename T> gb_internal void mpsc_destroy(MPSCQueue<T> *q);
|
||||||
template <typename T> gb_internal isize mpsc_enqueue(MPSCQueue<T> *q, T const &value);
|
template <typename T> gb_internal isize mpsc_enqueue(MPSCQueue<T> *q, T const &value);
|
||||||
template <typename T> gb_internal bool mpsc_dequeue(MPSCQueue<T> *q, T *value_);
|
template <typename T> gb_internal bool mpsc_dequeue(MPSCQueue<T> *q, T *value_);
|
||||||
template <typename T> gb_internal MPSCNode<T> *mpsc_tail (MPSCQueue<T> *q);
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
gb_internal void mpsc_init(MPSCQueue<T> *q, gbAllocator const &allocator) {
|
gb_internal void mpsc_init(MPSCQueue<T> *q, gbAllocator const &allocator) {
|
||||||
q->allocator = allocator;
|
q->allocator = allocator;
|
||||||
q->count.store(0, std::memory_order_relaxed);
|
q->sentinel.next.store(nullptr, std::memory_order_relaxed);
|
||||||
q->head.store(&q->sentinel, std::memory_order_relaxed);
|
q->head.store(&q->sentinel, std::memory_order_relaxed);
|
||||||
q->tail.store(&q->sentinel, std::memory_order_relaxed);
|
q->tail.store(&q->sentinel, std::memory_order_relaxed);
|
||||||
|
q->count.store(0, std::memory_order_relaxed);
|
||||||
q->sentinel.next.store(nullptr, std::memory_order_relaxed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
gb_internal void mpsc_destroy(MPSCQueue<T> *q) {
|
gb_internal void mpsc_destroy(MPSCQueue<T> *q) {
|
||||||
while (mpsc_dequeue(q, (T *)nullptr)) {}
|
GB_ASSERT(q->count.load() == 0);
|
||||||
// DO NOTHING for the time being
|
|
||||||
// free the nodes later
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
gb_internal MPSCNode<T> *mpsc_alloc_node(MPSCQueue<T> *q, T const &value) {
|
gb_internal MPSCNode<T> *mpsc_alloc_node(MPSCQueue<T> *q, T const &value) {
|
||||||
auto new_node = gb_alloc_item(q->allocator, MPSCNode<T>);
|
auto new_node = gb_alloc_item(q->allocator, MPSCNode<T>);
|
||||||
@@ -51,7 +46,7 @@ gb_internal MPSCNode<T> *mpsc_alloc_node(MPSCQueue<T> *q, T const &value) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
gb_internal void mpsc_free_node(MPSCQueue<T> *q, MPSCNode<T> *node) {
|
gb_internal void mpsc_free_node(MPSCQueue<T> *q, MPSCNode<T> *node) {
|
||||||
// TODO(bill): reuse the free nodes
|
// TODO(bill): determine a good way to handle the freed nodes rather than letting them leak
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -59,7 +54,7 @@ gb_internal isize mpsc_enqueue(MPSCQueue<T> *q, MPSCNode<T> *node) {
|
|||||||
node->next.store(nullptr, std::memory_order_relaxed);
|
node->next.store(nullptr, std::memory_order_relaxed);
|
||||||
auto prev = q->head.exchange(node, std::memory_order_acq_rel);
|
auto prev = q->head.exchange(node, std::memory_order_acq_rel);
|
||||||
prev->next.store(node, std::memory_order_release);
|
prev->next.store(node, std::memory_order_release);
|
||||||
isize count = 1 + q->count.fetch_add(1, std::memory_order_acq_rel);
|
isize count = 1 + q->count.fetch_add(1, std::memory_order_relaxed);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +72,8 @@ gb_internal bool mpsc_dequeue(MPSCQueue<T> *q, T *value_) {
|
|||||||
if (next) {
|
if (next) {
|
||||||
q->tail.store(next, std::memory_order_relaxed);
|
q->tail.store(next, std::memory_order_relaxed);
|
||||||
if (value_) *value_ = next->value;
|
if (value_) *value_ = next->value;
|
||||||
|
q->count.fetch_sub(1, std::memory_order_relaxed);
|
||||||
mpsc_free_node(q, tail);
|
mpsc_free_node(q, tail);
|
||||||
q->count.fetch_sub(1, std::memory_order_acq_rel);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
GB_ASSERT(q->count.load(std::memory_order_acquire) == 0);
|
GB_ASSERT(q->count.load(std::memory_order_acquire) == 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user