You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sledge/runtime/include/hash.h

53 lines
1.3 KiB

#pragma once
#include "hashmap.h"
#include "lock.h"
#include "xmalloc.h"
typedef struct
{
struct hashmap* map;
lock_t lock;
}lockhashmap;
static inline lockhashmap
*hashmap_lock_new(
size_t elsize, size_t cap, uint64_t seed0,
uint64_t seed1,
uint64_t (*hash)(const void *item, uint64_t seed0, uint64_t seed1),
int (*compare)(const void *a, const void *b, void *udata),
void (*elfree)(void *item),
void *udata
)
{
lockhashmap* node = (lockhashmap *)xmalloc(sizeof(lockhashmap));
node->map = hashmap_new(elsize, cap, seed0, seed1, hash, compare, elfree, udata);
LOCK_INIT(&node->lock);
return node;
}
/*void threadsafe_hashmap_free(ThreadSafeHashmap *thm) {
if (thm) {
spinlock_acquire(&thm->lock);
hashmap_free(thm->map);
spinlock_release(&thm->lock);
spinlock_destroy(&thm->lock);
free(thm);
}
}
bool threadsafe_hashmap_set(ThreadSafeHashmap *thm, const void *item) {
spinlock_acquire(&thm->lock);
const void *result = hashmap_set(thm->map, item);
spinlock_release(&thm->lock);
return result != NULL;
}
const void *threadsafe_hashmap_get(ThreadSafeHashmap *thm, const void *item) {
spinlock_acquire(&thm->lock);
const void *result = hashmap_get(thm->map, item);
spinlock_release(&thm->lock);
return result;
}
*/