Project

General

Profile

Feature #600 » 0091-Add-at_thread_exit-callback-support.patch

main, S3_3 - Marko Lindqvist, 05/29/2025 02:31 AM

View differences:

utility/fcthread.c
#include "fcthread.h"
static at_thread_exit_cb *ate_cb = nullptr;
/*******************************************************************//**
Register callback to be called whenever a thread finishes.
This can be called only once. Latter calls will cause an error message
and return FALSE.
***********************************************************************/
bool register_at_thread_exit_callback(at_thread_exit_cb *cb)
{
if (ate_cb != nullptr) {
log_error("Trying to register multiple at_thread_exit callbacks.");
log_error("That's not supported yet.");
return FALSE;
}
ate_cb = cb;
return TRUE;
}
/*******************************************************************//**
Called at thread exit by all the thread implementations.
***********************************************************************/
static void at_thread_exit(void)
{
if (ate_cb != nullptr) {
ate_cb();
}
}
#ifdef FREECIV_C11_THR
struct fc_thread_wrap_data {
......
free(data);
at_thread_exit();
return EXIT_SUCCESS;
}
......
free(data);
at_thread_exit();
return nullptr;
}
......
free(data);
at_thread_exit();
return 0;
}
utility/fcthread.h
bool has_thread_cond_impl(void);
typedef void (at_thread_exit_cb)(void);
bool register_at_thread_exit_callback(at_thread_exit_cb *cb);
#ifdef __cplusplus
}
#endif /* __cplusplus */
(1-1/2)