summaryrefslogtreecommitdiff
path: root/funcs/func_lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'funcs/func_lock.c')
-rw-r--r--funcs/func_lock.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/funcs/func_lock.c b/funcs/func_lock.c
index 38c3aea35..060fcb809 100644
--- a/funcs/func_lock.c
+++ b/funcs/func_lock.c
@@ -486,9 +486,11 @@ static int unload_module(void)
ast_custom_function_unregister(&trylock_function);
ast_custom_function_unregister(&unlock_function);
- pthread_cancel(broker_tid);
- pthread_kill(broker_tid, SIGURG);
- pthread_join(broker_tid, NULL);
+ if (broker_tid != AST_PTHREADT_NULL) {
+ pthread_cancel(broker_tid);
+ pthread_kill(broker_tid, SIGURG);
+ pthread_join(broker_tid, NULL);
+ }
AST_LIST_UNLOCK(&locklist);
@@ -500,7 +502,14 @@ static int load_module(void)
int res = ast_custom_function_register(&lock_function);
res |= ast_custom_function_register(&trylock_function);
res |= ast_custom_function_register(&unlock_function);
- ast_pthread_create_background(&broker_tid, NULL, lock_broker, NULL);
+
+ if (ast_pthread_create_background(&broker_tid, NULL, lock_broker, NULL)) {
+ ast_log(LOG_ERROR, "Failed to start lock broker thread. Unloading func_lock module.\n");
+ broker_tid = AST_PTHREADT_NULL;
+ unload_module();
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
return res;
}