mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 05:16:21 +00:00
fix(ai): standardize lock handling in _ai_invoke_callback
Take the global lock mutex before invoking all callbacks (success and error) to ensure thread-safety. Previously some paths took the lock and others did not, creating asymmetric behavior that could lead to data races when callbacks access UI state.
This commit is contained in:
@@ -111,8 +111,10 @@ _ai_invoke_callback(ai_callback_data_t* cb_data)
|
|||||||
{
|
{
|
||||||
log_debug("[AI-CALLBACK] _ai_invoke_callback: is_error=%d, response_cb=%p, error_cb=%p",
|
log_debug("[AI-CALLBACK] _ai_invoke_callback: is_error=%d, response_cb=%p, error_cb=%p",
|
||||||
cb_data->is_error, (void*)cb_data->response_cb, (void*)cb_data->error_cb);
|
cb_data->is_error, (void*)cb_data->response_cb, (void*)cb_data->error_cb);
|
||||||
/* profanity uses ncurses, not GLib main loop, so call directly */
|
/* Take the global lock to ensure thread-safety when invoking callbacks that may access UI state. */
|
||||||
|
pthread_mutex_lock(&lock);
|
||||||
_ai_callback_invoke(cb_data);
|
_ai_callback_invoke(cb_data);
|
||||||
|
pthread_mutex_unlock(&lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================================
|
/* ========================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user