hashmap_mpause

This commit is contained in:
aiden 2023-02-02 13:58:30 +00:00
parent fc0013a69c
commit ffe67f5869
Signed by: aiden
GPG Key ID: EFA9C74AEBF806E0
4 changed files with 20 additions and 11 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "src/ifc"]
path = src/ifc
url = ssh://git@git.tcp.direct:2222/aiden/ifc.git
url = https://git.tcp.direct/aiden/ifc.git

View File

@ -1,9 +1,9 @@
#define HASHMAP_HASH_FUNCTION(key) (*(uint64_t *)key ^ 9268326398 /* arbitrary integer */)
#include "hashmap.h"
#include "src/hashmap.h"
#include <time.h>
#include <stdio.h>
#define N_THREADS 16
#define N_THREADS 8
#define _N_BUCKETS 24000000
#define N_BUCKETS (size_t)((_N_BUCKETS / N_THREADS) * N_THREADS)
@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {
void *fuck;
pthread_join(threads[x], &(fuck));
}
printf("success! %lfs\n", rc() - time);
printf("success! %lfs\ndeleting %zu values...\n", rc() - time, N_BUCKETS);
for (size_t x = 0; x < N_THREADS; ++x) {
pthread_create(&(threads[x]), NULL, (void *)&(deletet), &(gosh[x]));

View File

@ -34,7 +34,16 @@
#include <stdatomic.h>
#include <pthread.h>
#include <string.h>
#include <immintrin.h>
#if __has_builtin(__builtin_ia32_pause)
#define hashmap_mpause() __builtin_ia32_pause()
#elif __has_builtin(__builtin_arm_isb)
#define hashmap_mpause() __builtin_arm_isb(15)
#elif __has_builtin(__builtin_arm_yield)
#define hashmap_mpause() __builtin_arm_yield()
#else
#define hashmap_mpause() (void)0
#endif
#include "ifc/ifc.h"
@ -157,7 +166,7 @@ static bool _hashmap_find(
struct hashmap_bucket *bucket = &(buckets[bucket_idx]);
while (__atomic_test_and_set(&(bucket->lock), __ATOMIC_ACQUIRE)) {
_mm_pause();
hashmap_mpause();
}
for (size_t it = 0;; ++it) {
@ -184,7 +193,7 @@ static bool _hashmap_find(
}
while (__atomic_test_and_set(&(next_bucket->lock), __ATOMIC_ACQUIRE)) {
_mm_pause();
hashmap_mpause();
}
__atomic_clear(&(bucket->lock), __ATOMIC_RELEASE);
@ -216,7 +225,7 @@ static void _hashmap_cfi(
(*current) = array;
}
while (__atomic_test_and_set(&((*current)->lock), __ATOMIC_ACQUIRE)) {
_mm_pause();
hashmap_mpause();
}
__atomic_clear(old_lock, __ATOMIC_RELEASE);
@ -585,7 +594,7 @@ static enum hashmap_cas_result hashmap_cas(
next_bucket = buckets;
}
while (__atomic_test_and_set(&(next_bucket->lock), __ATOMIC_ACQUIRE)) {
_mm_pause();
hashmap_mpause();
}
if (next_bucket->protected.kv == NULL || next_bucket->protected.psl == 0) {
__atomic_clear(&(bucket->lock), __ATOMIC_RELEASE);
@ -743,7 +752,7 @@ struct hashmap *hashmap_create(
goto err6;
}
hashmap->reference_count = 0;
hashmap->reference_count = 1;
*(hashmap_callback *)&(hashmap->callback) = callback;

@ -1 +1 @@
Subproject commit ecf24f6e7605f0f90e99f5d3cebe207060bc8da7
Subproject commit 8fe92624ef71c22dd2d3c25c95b234143f609158