mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-16 16:58:35 +00:00
add nolock to hash and make it default
This commit is contained in:
parent
4517a511d5
commit
ec0906e2d4
@ -95,7 +95,8 @@ typedef enum {
|
|||||||
KS_HASH_FLAG_FREE_KEY = (1 << 1),
|
KS_HASH_FLAG_FREE_KEY = (1 << 1),
|
||||||
KS_HASH_FLAG_FREE_VALUE = (1 << 2),
|
KS_HASH_FLAG_FREE_VALUE = (1 << 2),
|
||||||
KS_HASH_FLAG_RWLOCK = (1 << 3),
|
KS_HASH_FLAG_RWLOCK = (1 << 3),
|
||||||
KS_HASH_FLAG_DUP_CHECK = (1 << 4)
|
KS_HASH_FLAG_DUP_CHECK = (1 << 4),
|
||||||
|
KS_HASH_FLAG_NOLOCK = (1 << 5)
|
||||||
} ks_hash_flag_t;
|
} ks_hash_flag_t;
|
||||||
|
|
||||||
#define KS_HASH_FREE_BOTH KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE
|
#define KS_HASH_FREE_BOTH KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE
|
||||||
@ -134,7 +135,7 @@ ks_hash_create_ex(ks_hash_t **hp, unsigned int minsize,
|
|||||||
* @param h the ks_hash to insert into
|
* @param h the ks_hash to insert into
|
||||||
* @param k the key - ks_hash claims ownership and will free on removal
|
* @param k the key - ks_hash claims ownership and will free on removal
|
||||||
* @param v the value - does not claim ownership
|
* @param v the value - does not claim ownership
|
||||||
* @return non-zero for successful insertion
|
* @return KS_STATUS_SUCCESS for successful insertion
|
||||||
*
|
*
|
||||||
* This function will cause the table to expand if the insertion would take
|
* This function will cause the table to expand if the insertion would take
|
||||||
* the ratio of entries to table size over the maximum load factor.
|
* the ratio of entries to table size over the maximum load factor.
|
||||||
@ -147,7 +148,7 @@ ks_hash_create_ex(ks_hash_t **hp, unsigned int minsize,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
KS_DECLARE(int) ks_hash_insert_ex(ks_hash_t *h, void *k, void *v, ks_hash_flag_t flags, ks_hash_destructor_t destructor);
|
KS_DECLARE(ks_status_t) ks_hash_insert_ex(ks_hash_t *h, void *k, void *v, ks_hash_flag_t flags, ks_hash_destructor_t destructor);
|
||||||
#define ks_hash_insert(_h, _k, _v) ks_hash_insert_ex(_h, _k, _v, 0, NULL)
|
#define ks_hash_insert(_h, _k, _v) ks_hash_insert_ex(_h, _k, _v, 0, NULL)
|
||||||
|
|
||||||
#define DEFINE_KS_HASH_INSERT(fnname, keytype, valuetype) \
|
#define DEFINE_KS_HASH_INSERT(fnname, keytype, valuetype) \
|
||||||
|
@ -211,7 +211,11 @@ ks_hash_create_ex(ks_hash_t **hp, unsigned int minsize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags == KS_HASH_FLAG_DEFAULT) {
|
if (flags == KS_HASH_FLAG_DEFAULT) {
|
||||||
flags = KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_RWLOCK;
|
flags = KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_NOLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & KS_HASH_FLAG_NOLOCK)) {
|
||||||
|
flags &= ~KS_HASH_FLAG_RWLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ks_assert(pool);
|
ks_assert(pool);
|
||||||
@ -240,7 +244,9 @@ ks_hash_create_ex(ks_hash_t **hp, unsigned int minsize,
|
|||||||
ks_rwl_create(&h->rwl, h->pool);
|
ks_rwl_create(&h->rwl, h->pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(flags & KS_HASH_FLAG_NOLOCK)) {
|
||||||
ks_mutex_create(&h->mutex, KS_MUTEX_FLAG_DEFAULT, h->pool);
|
ks_mutex_create(&h->mutex, KS_MUTEX_FLAG_DEFAULT, h->pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (NULL == h) abort(); /*oom*/
|
if (NULL == h) abort(); /*oom*/
|
||||||
@ -377,7 +383,7 @@ static void * _ks_hash_remove(ks_hash_t *h, void *k, unsigned int hashvalue, uns
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
KS_DECLARE(int)
|
KS_DECLARE(ks_status_t)
|
||||||
ks_hash_insert_ex(ks_hash_t *h, void *k, void *v, ks_hash_flag_t flags, ks_hash_destructor_t destructor)
|
ks_hash_insert_ex(ks_hash_t *h, void *k, void *v, ks_hash_flag_t flags, ks_hash_destructor_t destructor)
|
||||||
{
|
{
|
||||||
struct entry *e;
|
struct entry *e;
|
||||||
@ -404,7 +410,6 @@ ks_hash_insert_ex(ks_hash_t *h, void *k, void *v, ks_hash_flag_t flags, ks_hash_
|
|||||||
index = indexFor(h->tablelength, hashvalue);
|
index = indexFor(h->tablelength, hashvalue);
|
||||||
}
|
}
|
||||||
e = (struct entry *)ks_pool_alloc(h->pool, sizeof(struct entry));
|
e = (struct entry *)ks_pool_alloc(h->pool, sizeof(struct entry));
|
||||||
if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
|
|
||||||
e->h = hashvalue;
|
e->h = hashvalue;
|
||||||
e->k = k;
|
e->k = k;
|
||||||
e->v = v;
|
e->v = v;
|
||||||
@ -415,13 +420,15 @@ ks_hash_insert_ex(ks_hash_t *h, void *k, void *v, ks_hash_flag_t flags, ks_hash_
|
|||||||
|
|
||||||
ks_hash_write_unlock(h);
|
ks_hash_write_unlock(h);
|
||||||
|
|
||||||
return -1;
|
return KS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KS_DECLARE(void) ks_hash_write_lock(ks_hash_t *h)
|
KS_DECLARE(void) ks_hash_write_lock(ks_hash_t *h)
|
||||||
{
|
{
|
||||||
if ((h->flags & KS_HASH_FLAG_RWLOCK)) {
|
if ((h->flags & KS_HASH_FLAG_NOLOCK)) {
|
||||||
|
return;
|
||||||
|
} else if ((h->flags & KS_HASH_FLAG_RWLOCK)) {
|
||||||
ks_rwl_write_lock(h->rwl);
|
ks_rwl_write_lock(h->rwl);
|
||||||
} else {
|
} else {
|
||||||
ks_mutex_lock(h->mutex);
|
ks_mutex_lock(h->mutex);
|
||||||
@ -430,7 +437,9 @@ KS_DECLARE(void) ks_hash_write_lock(ks_hash_t *h)
|
|||||||
|
|
||||||
KS_DECLARE(void) ks_hash_write_unlock(ks_hash_t *h)
|
KS_DECLARE(void) ks_hash_write_unlock(ks_hash_t *h)
|
||||||
{
|
{
|
||||||
if ((h->flags & KS_HASH_FLAG_RWLOCK)) {
|
if ((h->flags & KS_HASH_FLAG_NOLOCK)) {
|
||||||
|
return;
|
||||||
|
} else if ((h->flags & KS_HASH_FLAG_RWLOCK)) {
|
||||||
ks_rwl_write_unlock(h->rwl);
|
ks_rwl_write_unlock(h->rwl);
|
||||||
} else {
|
} else {
|
||||||
ks_mutex_unlock(h->mutex);
|
ks_mutex_unlock(h->mutex);
|
||||||
@ -565,8 +574,6 @@ KS_DECLARE(void) ks_hash_last(ks_hash_iterator_t **iP)
|
|||||||
{
|
{
|
||||||
ks_hash_iterator_t *i = *iP;
|
ks_hash_iterator_t *i = *iP;
|
||||||
|
|
||||||
//ks_assert(i->locked != KS_READLOCKED || (i->h->flags & KS_HASH_FLAG_RWLOCK));
|
|
||||||
|
|
||||||
if (i->locked == KS_READLOCKED) {
|
if (i->locked == KS_READLOCKED) {
|
||||||
ks_mutex_lock(i->h->mutex);
|
ks_mutex_lock(i->h->mutex);
|
||||||
i->h->readers--;
|
i->h->readers--;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user