From ad8ce3541d0f7619082b3d5d8806d2fee169d1d2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 7 Jan 2025 13:38:09 -0400 Subject: [PATCH] MT#61822 add RWLOCK_STATIC_INIT Change-Id: I6718df967b70554a32c3caddcb4e29af4fb6d7f0 --- daemon/call.c | 3 +-- daemon/dtls.c | 3 +-- daemon/media_socket.c | 4 +--- lib/auxlib.h | 1 + lib/bufferpool.c | 4 +--- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 0b8c5a685..b377acfb9 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -55,7 +55,7 @@ struct xmlrpc_helper { GQueue strings; }; -rwlock_t rtpe_callhash_lock; +rwlock_t rtpe_callhash_lock = RWLOCK_STATIC_INIT; rtpe_calls_ht rtpe_callhash; struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS]; __thread call_t *call_memory_arena; @@ -587,7 +587,6 @@ int call_init(void) { rtpe_callhash = rtpe_calls_ht_new(); if (!t_hash_table_is_set(rtpe_callhash)) return -1; - rwlock_init(&rtpe_callhash_lock); for (int i = 0; i < NUM_CALL_ITERATORS; i++) mutex_init(&rtpe_call_iterators[i].lock); diff --git a/daemon/dtls.c b/daemon/dtls.c index 680d0a5d1..e97e9c1a9 100644 --- a/daemon/dtls.c +++ b/daemon/dtls.c @@ -99,7 +99,7 @@ const int num_hash_funcs = G_N_ELEMENTS(hash_funcs); static struct dtls_cert *__dtls_cert; -static rwlock_t __dtls_cert_lock; +static rwlock_t __dtls_cert_lock = RWLOCK_STATIC_INIT; @@ -379,7 +379,6 @@ int dtls_init(void) { int i; char *p; - rwlock_init(&__dtls_cert_lock); if (cert_init()) return -1; diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 7671eb769..575bb437e 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -435,7 +435,7 @@ static GQueue __preferred_lists_for_family[__SF_LAST]; GQueue all_local_interfaces = G_QUEUE_INIT; TYPED_GHASHTABLE(local_sockets_ht, endpoint_t, stream_fd, endpoint_hash, endpoint_eq, NULL, stream_fd_put) -static rwlock_t local_media_socket_endpoints_lock; +static rwlock_t local_media_socket_endpoints_lock = RWLOCK_STATIC_INIT; static local_sockets_ht local_media_socket_endpoints; __thread struct bufferpool *media_bufferpool; @@ -881,7 +881,6 @@ void interfaces_init(intf_config_q *interfaces) { } local_media_socket_endpoints = local_sockets_ht_new(); - rwlock_init(&local_media_socket_endpoints_lock); } void interfaces_exclude_port(unsigned int port) { @@ -3268,7 +3267,6 @@ void interfaces_free(void) { t_hash_table_destroy(local_media_socket_endpoints); local_media_socket_endpoints = local_sockets_ht_null(); - rwlock_destroy(&local_media_socket_endpoints_lock); } diff --git a/lib/auxlib.h b/lib/auxlib.h index cfc66a075..8416f5398 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -135,6 +135,7 @@ typedef pthread_cond_t cond_t; #define rwlock_lock_w(l) __debug_rwlock_lock_w(l, __FILE__, __LINE__) #define rwlock_trylock_w(l) __debug_rwlock_trylock_w(l, __FILE__, __LINE__) #define rwlock_unlock_w(l) __debug_rwlock_unlock_w(l, __FILE__, __LINE__) +#define RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER #define cond_init(c) __debug_cond_init(c, __FILE__, __LINE__) #define cond_wait(c,m) __debug_cond_wait(c,m, __FILE__, __LINE__) diff --git a/lib/bufferpool.c b/lib/bufferpool.c index 28c2a22cb..22bf43f21 100644 --- a/lib/bufferpool.c +++ b/lib/bufferpool.c @@ -29,7 +29,7 @@ struct bpool_shard { }; // sorted list of all shards for quick bsearch -static rwlock_t bpool_shards_lock; +static rwlock_t bpool_shards_lock = RWLOCK_STATIC_INIT; static GPtrArray *bpool_shards; static struct bufferpool *bufferpool_new_common(void *(*alloc)(size_t), size_t shard_size) { @@ -307,12 +307,10 @@ void bufferpool_destroy(struct bufferpool *bp) { } void bufferpool_init(void) { - rwlock_init(&bpool_shards_lock); bpool_shards = g_ptr_array_new(); } void bufferpool_cleanup(void) { - rwlock_destroy(&bpool_shards_lock); assert(bpool_shards->len == 0); g_ptr_array_free(bpool_shards, true); }