void exmpp_ht_dump_keys(struct exmpp_hashtable *ht) { unsigned int i, j; struct exmpp_ht_entry *entry; if (ht == NULL || ht->entries == NULL) return; #if defined(USE_RWLOCK) erl_drv_rwlock_rlock(ht->lock); #endif for (i = 0; i < ht->length; ++i) { entry = ht->entries[i]; j = 0; while (entry != NULL) { if (j == 0) printf(" %3u: '%s'\r\n", i, entry->key); else printf(" '%s'\r\n", entry->key); entry = entry->next; ++j; } } #if defined(USE_RWLOCK) erl_drv_rwlock_runlock(ht->lock); #endif }
void rwlock_rdunlock(rwlock_t* lock){ #ifdef USE_PTHREAD pthread_rwlock_unlock(lock); #elif defined USE_ETHREAD erl_drv_rwlock_runlock(*lock); #endif }
void * exmpp_ht_fetch(struct exmpp_hashtable *ht, const char *key, int key_len) { struct exmpp_ht_entry *entry; unsigned int hash, index; if (ht == NULL || ht->entries == NULL) return (NULL); hash = key_len == -1 ? ht_hash(key) : ht_hash_len(key, key_len); #if defined(USE_RWLOCK) erl_drv_rwlock_rlock(ht->lock); #endif index = hash % ht->length; entry = ht->entries[index]; while (entry != NULL) { /* Check hash value to short circuit heavier comparison. */ if (entry->hash == hash && ((key_len == -1 && strcmp(entry->key, key) == 0) || (entry->key_len == key_len && strncmp(entry->key, key, key_len) == 0))) { #if defined(USE_RWLOCK) erl_drv_rwlock_runlock(ht->lock); #endif return (entry->value); } entry = entry->next; } #if defined(USE_RWLOCK) erl_drv_rwlock_runlock(ht->lock); #endif return (NULL); }
void enif_rwlock_runlock(ErlNifRWLock *rwlck) { erl_drv_rwlock_runlock(rwlck); }