10.2. Threading API
10.2.1. Overview
If Anjay is compiled with thread safety enabled (WITH_THREAD_SAFETY CMake
option), it requires some basic threading primitives to be implemented for the
thread safety features to work properly.
The same threading primitives are additionally used by the avs_net and
avs_log modules regardless of whether thread safety is enabled or not.
The specific requirements are:
avs_netrequiresavs_init_once(),avs_logand Anjay thread safety requireavs_mutex_create(),avs_mutex_cleanup(),avs_mutex_lock(),avs_mutex_unlock(), andavs_init_once().
In addition, avs_sched optionally depends on avs_condvar_create(),
avs_condvar_cleanup(), avs_condvar_notify_all() as well as
avs_mutex_* APIs. The dependency can be controlled with
WITH_SCHEDULER_THREAD_SAFE CMake option. This option normally has the same
setting as WITH_THREAD_SAFETY.
There are two independent implementations of the threading API for compatibility with most platforms:
Note
You may use either of the implementations listed above as a reference for writing your own if necessary.
10.2.2. List of functions to implement
If, for some reason neither of the default implementations is suitable:
Use
WITH_CUSTOM_AVS_THREADING=ONwhen running CMake on Anjay,Provide an implementation of:
avs_mutex_create(),avs_mutex_cleanup(),avs_init_once(),avs_mutex_lock(),avs_mutex_unlock().
And if you use thread-safe scheduler, also provide implementation for:
avs_condvar_create(),avs_condvar_cleanup(),avs_condvar_notify_all().
Note
For signatures and detailed description of listed functions, see
Note
If you intend to operate the library in a single-threaded fashion, you may provide no-op stubs (returning success) of all mentioned primitives.