From cb280ab14bfb1fbbd6dc6fd24c22bfa394ed06f6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 10 Feb 2016 14:55:13 -0600 Subject: [PATCH] FS-8821 #resolve [Check for status of executed operation] --- src/include/switch_core.h | 8 ++++---- src/switch_core_hash.c | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 16669672e8..e9e5082436 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1443,18 +1443,18 @@ SWITCH_DECLARE(void *) switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ \param hash the hash to delete from \param key the key from which to delete the data \param mutex optional mutex to lock - \return SWITCH_STATUS_SUCCESS if the data is deleted + \return a pointer to the deleted data */ -SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex); +SWITCH_DECLARE(void *) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex); /*! \brief Delete data from a hash based on desired key \param hash the hash to delete from \param key the key from which to delete the data \param mutex optional rwlock to wrlock - \return SWITCH_STATUS_SUCCESS if the data is deleted + \return a pointer to the deleted data */ -SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock); +SWITCH_DECLARE(void *) switch_core_hash_delete_wrlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock); /*! \brief Delete data from a hash based on callback function diff --git a/src/switch_core_hash.c b/src/switch_core_hash.c index 29427013b0..51fc53887c 100644 --- a/src/switch_core_hash.c +++ b/src/switch_core_hash.c @@ -66,32 +66,36 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_destructor(switch_hash_t SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t *hash, const char *key, const void *data, switch_mutex_t *mutex) { + switch_status_t status = SWITCH_STATUS_FALSE; + if (mutex) { switch_mutex_lock(mutex); } - switch_core_hash_insert(hash, key, data); + status = switch_core_hash_insert(hash, key, data); if (mutex) { switch_mutex_unlock(mutex); } - return SWITCH_STATUS_SUCCESS; + return status; } SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock) { + switch_status_t status = SWITCH_STATUS_FALSE; + if (rwlock) { switch_thread_rwlock_wrlock(rwlock); } - switch_core_hash_insert(hash, key, data); + status = switch_core_hash_insert(hash, key, data); if (rwlock) { switch_thread_rwlock_unlock(rwlock); } - return SWITCH_STATUS_SUCCESS; + return status; } SWITCH_DECLARE(void *) switch_core_hash_delete(switch_hash_t *hash, const char *key) @@ -99,8 +103,10 @@ SWITCH_DECLARE(void *) switch_core_hash_delete(switch_hash_t *hash, const char * return switch_hashtable_remove(hash, (void *)key); } -SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t *hash, const char *key, switch_mutex_t *mutex) +SWITCH_DECLARE(void *) switch_core_hash_delete_locked(switch_hash_t *hash, const char *key, switch_mutex_t *mutex) { + void *ret = NULL; + if (mutex) { switch_mutex_lock(mutex); } @@ -111,22 +117,24 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t *ha switch_mutex_unlock(mutex); } - return SWITCH_STATUS_SUCCESS; + return ret; } -SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock) +SWITCH_DECLARE(void *) switch_core_hash_delete_wrlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock) { + void *ret = NULL; + if (rwlock) { switch_thread_rwlock_wrlock(rwlock); } - switch_core_hash_delete(hash, key); + ret = switch_core_hash_delete(hash, key); if (rwlock) { switch_thread_rwlock_unlock(rwlock); } - return SWITCH_STATUS_SUCCESS; + return ret; } SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(switch_hash_t *hash, switch_hash_delete_callback_t callback, void *pData) {