Mstdlib-1.24.0
|
Enumerations | |
enum | M_thread_model_t { M_THREAD_MODEL_INVALID = -1 , M_THREAD_MODEL_NATIVE = 0 , M_THREAD_MODEL_COOP } |
Functions | |
M_bool | M_thread_init (M_thread_model_t model) |
M_bool | M_thread_active_model (M_thread_model_t *model, const char **model_name) |
M_bool | M_thread_destructor_insert (void(*destructor)(void)) |
void | M_thread_destructor_remove (void(*destructor)(void)) |
void | M_library_cleanup (void) |
void | M_library_cleanup_register (void(*cleanup_cb)(void *arg), void *arg) |
size_t | M_thread_count (void) |
size_t | M_thread_num_cpu_cores (void) |
Thread System Initialization, Destruction, and Information
enum M_thread_model_t |
M_bool M_thread_init | ( | M_thread_model_t | model | ) |
Initialize the thread model (system).
This should be called before any other thread function is used. This will initialize the specified threading system. If this is not called before a thread function is used then the native threading model will be automatically initialized.
Only one thread model can be use at any given time.
[in] | model | The thread model that should be used for threading. |
M_bool M_thread_active_model | ( | M_thread_model_t * | model, |
const char ** | model_name | ||
) |
Get the active thread model.
[out] | model | The active model. |
[out] | model_name | The textual name of the model. This will provide descriptive information such as what is the underlying native threading model. |
M_bool M_thread_destructor_insert | ( | void(*)(void) | destructor | ) |
Adds a function to be called each time a thread finishes.
Some libraries (OpenSSL in particular) keep their own per thread memory store. This allows registering functions to be called to handle this situation.
OpenSSL keeps a per-thread error state which must be cleaned up at thread destruction otherwise it will leak memory like crazy. Wrap ERR_remove_state(0); in a function that doesn't take any arugments, then register the function and this problem is solved.
Registered functions will be called in the order they were added.
[in] | destructor | The function to register. |
void M_thread_destructor_remove | ( | void(*)(void) | destructor | ) |
Remove a function from the list of function to be called each time a thread finished.
[in] | destructor | The function to remove. |
void M_library_cleanup | ( | void | ) |
Thread-safe library cleanup.
Cleans up any initialized static/global members by the library. Useful to be called at the end of program execution to free memory or other resources, especially if running under a leak checker such as Valgrind.
void M_library_cleanup_register | ( | void(*)(void *arg) | cleanup_cb, |
void * | arg | ||
) |
Registers a callback to be called during M_library_cleanup().
There is no way to 'unregister' a callback, so it must be ensured the callback will remain valid until the end of program execution.
[in] | cleanup_cb | Callback to call for cleanup |
[in] | arg | Optional argument to be passed to the callback. |
size_t M_thread_count | ( | void | ) |
Get the number of actively running threads. This count includes the main process thread.
This count does not include the threads that have finished but are still joinable.
size_t M_thread_num_cpu_cores | ( | void | ) |
Retrieve the count of CPU cores that are online and usable. When using cooperative threading, only 1 cpu core is usable.