void rwlock_rwunlock(rwlock_t* lock){ #ifdef USE_PTHREAD pthread_rwlock_unlock(lock); #elif defined USE_ETHREAD erl_drv_rwlock_rwunlock(*lock); #endif }
int exmpp_ht_store(struct exmpp_hashtable *ht, const char *key, int key_len, void *value) { unsigned int index; struct exmpp_ht_entry *entry; if (ht == NULL || ht->entries == NULL) return (-1); /* Allocate the new entry. */ entry = driver_alloc(sizeof(*entry)); if (entry == NULL) return (-1); if (key_len == -1) { entry->hash = ht_hash(key); entry->key = exmpp_strdup(key); if (entry->key == NULL) return (-1); } else { entry->hash = ht_hash_len(key, key_len); entry->key = driver_alloc(key_len + 1); if (entry->key == NULL) return (-1); memcpy(entry->key, key, key_len); entry->key[key_len] = '\0'; } entry->key_len = key_len; entry->value = value; #if defined(USE_RWLOCK) erl_drv_rwlock_rwlock(ht->lock); #endif /* Expand the table is necessary. */ if (++(ht->entries_count) > ht->load_limit) { /* * Ignore the return value. If expand fails, we should * still try cramming just this value into the existing * table -- we may not have memory for a larger table, * but one more element may be ok. Next time we insert, * we'll try expanding again. */ ht_expand(ht); } /* Wire the new entry. */ index = entry->hash % ht->length; entry->next = ht->entries[index]; ht->entries[index] = entry; #if defined(USE_RWLOCK) erl_drv_rwlock_rwunlock(ht->lock); #endif return (0); }
void exmpp_ht_destroy(struct exmpp_hashtable *ht) { unsigned int i; struct exmpp_ht_entry *entry, *next; if (ht == NULL || ht->entries == NULL) return; #if defined(USE_RWLOCK) erl_drv_rwlock_rwlock(ht->lock); #endif for (i = 0; i < ht->length; ++i) { next = ht->entries[i]; while (next != NULL) { entry = next; next = next->next; driver_free(entry->key); if (ht->free_value != NULL) ht->free_value(entry->value); driver_free(entry); } } driver_free(ht->entries); ht->entries = NULL; ht->entries_count = 0; ht->length = 0; #if defined(USE_RWLOCK) erl_drv_rwlock_rwunlock(ht->lock); erl_drv_rwlock_destroy(ht->lock); #endif driver_free(ht); }
void enif_rwlock_rwunlock(ErlNifRWLock *rwlck) { erl_drv_rwlock_rwunlock(rwlck); }