Feature #600 » 0037-Add-at_thread_exit-callback-support.patch
utility/fcthread.c | ||
---|---|---|
#include "fcthread.h"
|
||
static at_thread_exit_cb *ate_cb = NULL;
|
||
/*******************************************************************//**
|
||
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 != NULL) {
|
||
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 != NULL) {
|
||
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 NULL;
|
||
}
|
||
... | ... | |
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 */
|
- « Previous
- 1
- 2
- Next »