void rwlock_init(rwlock_t * rwlock){ // rwlock_t * ret; #ifdef USE_PTHREAD // ret=(pthread_rwlock_t*)malloc(sizeof(pthread_rwlock_t)); pthread_rwlock_init(rwlock,NULL); // *ret = PTHREAD_RWLOCK_INITIALIZER; #elif defined USE_ETHREAD *rwlock = erl_drv_rwlock_create(NULL); #endif // return ret; }
struct exmpp_hashtable * exmpp_ht_create(unsigned int min_length, exmpp_ht_free_value_cb free_value) { struct exmpp_hashtable *ht; unsigned int pindex, length; /* Check requested length isn't too large. */ if (min_length > (1u << 30)) return (NULL); /* Enforce length as prime. */ length = primes[0]; for (pindex = 0; pindex < prime_table_length; ++pindex) { if (primes[pindex] > min_length) { length = primes[pindex]; break; } } ht = driver_alloc(sizeof(*ht)); if (ht == NULL) return (NULL); ht->entries = driver_alloc(length * sizeof(*(ht->entries))); if (ht->entries == NULL) { driver_free(ht); return (NULL); } memset(ht->entries, 0, length * sizeof(*(ht->entries))); #if defined(USE_RWLOCK) ht->lock = erl_drv_rwlock_create("exmpp_hashtable"); if (ht->lock == NULL) { driver_free(ht->entries); driver_free(ht); return (NULL); } #endif ht->length = length; ht->entries_count = 0; ht->load_limit = (unsigned int)ceil(length * MAX_LOAD_FACTOR); ht->prime_index = pindex; ht->free_value = free_value; return (ht); }
ErlNifRWLock* enif_rwlock_create(char *name) { return erl_drv_rwlock_create(name); }