summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 9d9d39702e..7f8a237047 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -28,6 +28,7 @@
#include "vty.h"
#include "command.h"
#include "libfrr.h"
+#include "frr_pthread.h"
DEFINE_MTYPE_STATIC(LIB, HASH, "Hash")
DEFINE_MTYPE_STATIC(LIB, HASH_BACKET, "Hash Bucket")
@@ -54,14 +55,12 @@ struct hash *hash_create_size(unsigned int size,
hash->name = name ? XSTRDUP(MTYPE_HASH, name) : NULL;
hash->stats.empty = hash->size;
- pthread_mutex_lock(&_hashes_mtx);
- {
+ frr_with_mutex(&_hashes_mtx) {
if (!_hashes)
_hashes = list_new();
listnode_add(_hashes, hash);
}
- pthread_mutex_unlock(&_hashes_mtx);
return hash;
}
@@ -311,8 +310,7 @@ struct list *hash_to_list(struct hash *hash)
void hash_free(struct hash *hash)
{
- pthread_mutex_lock(&_hashes_mtx);
- {
+ frr_with_mutex(&_hashes_mtx) {
if (_hashes) {
listnode_delete(_hashes, hash);
if (_hashes->count == 0) {
@@ -320,7 +318,6 @@ void hash_free(struct hash *hash)
}
}
}
- pthread_mutex_unlock(&_hashes_mtx);
XFREE(MTYPE_HASH, hash->name);