コード例 #1
0
ファイル: exmpp_driver.c プロジェクト: ASalimov/exmpp
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
}
コード例 #2
0
ファイル: lock.c プロジェクト: mihawk/yatce
void rwlock_rdlock(rwlock_t* lock){
#ifdef USE_PTHREAD
  pthread_rwlock_rdlock(lock);
#elif defined  USE_ETHREAD
  erl_drv_rwlock_rlock(*lock);
#endif
}
コード例 #3
0
ファイル: exmpp_driver.c プロジェクト: ASalimov/exmpp
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);
}
コード例 #4
0
ファイル: erl_nif.c プロジェクト: a5an0/otp
void enif_rwlock_rlock(ErlNifRWLock *rwlck) { erl_drv_rwlock_rlock(rwlck); }