mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-29 17:34:34 +00:00
Multithread min dep set by removing the set itself
This commit is contained in:
@@ -134,6 +134,44 @@ gb_internal bool ptr_set_update(PtrSet<T> *s, T ptr) { // returns true if it pre
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
gb_internal bool ptr_set_update_with_mutex(PtrSet<T> *s, T ptr, RWSpinLock *m) { // returns true if it previously existsed
|
||||
rwlock_acquire_upgrade(m);
|
||||
if (ptr_set_exists(s, ptr)) {
|
||||
rwlock_release_upgrade(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
rwlock_release_upgrade_and_acquire_write(m);
|
||||
defer (rwlock_release_write(m));
|
||||
|
||||
if (s->keys == nullptr) {
|
||||
ptr_set_init(s);
|
||||
} else if (ptr_set__full(s)) {
|
||||
ptr_set_grow(s);
|
||||
}
|
||||
GB_ASSERT(s->count < s->capacity);
|
||||
GB_ASSERT(s->capacity >= 0);
|
||||
|
||||
usize mask = s->capacity-1;
|
||||
u32 hash = ptr_map_hash_key(ptr);
|
||||
usize hash_index = (cast(usize)hash) & mask;
|
||||
GB_ASSERT(hash_index < s->capacity);
|
||||
for (usize i = 0; i < s->capacity; i++) {
|
||||
T *key = &s->keys[hash_index];
|
||||
GB_ASSERT(*key != ptr);
|
||||
if (*key == (T)PtrSet<T>::TOMBSTONE || *key == 0) {
|
||||
*key = ptr;
|
||||
s->count++;
|
||||
return false;
|
||||
}
|
||||
hash_index = (hash_index+1)&mask;
|
||||
}
|
||||
|
||||
GB_PANIC("ptr set out of memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
gb_internal T ptr_set_add(PtrSet<T> *s, T ptr) {
|
||||
ptr_set_update(s, ptr);
|
||||
|
||||
Reference in New Issue
Block a user