CRI ADX  Last Updated: 2024-07-17 10:47 p
Implementation With the User Multithread Model

Sample Directory

/CRIWARE/SDK/pc/samples/criatomex/user_multithread_framework


Sample Description

Perform the following procedure to run the Atom library's server processing in a separate thread created by the user.
  • When initializing the library, specify the user multithread model.
  • Create a thread, and then call the server processing function at a regular interval on that threads.
The following is a code sample that demonstrates this procedure.


#define USER_THREAD_PRIORITY_AUDIO (8)
#define USER_THREAD_PRIORITY_FILEACCESS (12)
#define USER_THREAD_PRIORITY_DATADECOMP (24)
:
/* Various server threads used in the user multithread model of ADX */
static void app_audio_process(void *arg)
{
(void)arg;
/* Audio processing by CRI ADX */
}
static void app_file_access_process(void *arg)
{
(void)arg;
/* File processing (read-in) by CRI File System */
/* The load completion callback function is invoked from this thread. */
criFs_ExecuteFileAccess();
}
static void app_data_decomp_process(void *arg)
{
(void)arg;
/* Data decompression processing by CRI File System*/
criFs_ExecuteDataDecompression();
}
:
void Sample_Initialize(void)
{
:
:
/* Specify user multithread model */
criAtomEx_SetDefaultConfig(&criatomex_config);
criatomex_config.thread_model = CRIATOMEX_THREAD_MODEL_USER_MULTI;
/* Library initialization */
smputl_initialize(&criatomex_config, NULL, 0);
:
:
/* Create a D-Bas, load the ACF file and register it */
/* Load ACB files and create ACB handles */
/* Create the voice pool, then create the player and get its status */
:
:
/* Create a thread for each processing */
{
CriUint32 thread_work_size;
thread_work_size = userThread_CalculateWorkSize();
/* Allocate thread work area */
user_audio_thread_work = user_alloc_func(NULL, thread_work_size);
user_file_access_thread_work = user_alloc_func(NULL, thread_work_size);
user_data_decomp_thread_work = user_alloc_func(NULL, thread_work_size);
/* Run audio processing on the same thread as CRI Atom library initialization */
user_audio_thread = userThread_Create(
user_audio_thread_work, thread_work_size,
app_audio_process, app_obj, USER_THREAD_PRIORITY_AUDIO, 0);
user_file_access_thread = userThread_Create(
user_file_access_thread_work, thread_work_size,
app_file_access_process, app_obj, USER_THREAD_PRIORITY_FILEACCESS, THREAD_AFFINITY_CORE2);
user_data_decomp_thread = userThread_Create(
user_data_decomp_thread_work, thread_work_size,
app_data_decomp_process, app_obj, USER_THREAD_PRIORITY_DATADECOMP, THREAD_AFFINITY_CORE2);
}
}
#define criAtomEx_SetDefaultConfig(p_config)
Assign the default values to the configuration structure used for the library's initialization.
Definition: cri_le_atom_ex.h:322
void criAtomEx_ExecuteAudioProcess(void)
Execute the server processing for user multithreading.
@ CRIATOMEX_THREAD_MODEL_USER_MULTI
User multithreading.
Definition: cri_le_atom_ex.h:1269



Attention
When you use the criAtomEx_ExecuteMain function to execute the server processing, it will wait for file reading within the function and therefore the processing will be locked for a number of V cycles.
If you use the user multithread model, run only the criAtomEx_ExecuteAudioProcess function on the main thread. Then, run other functions such as criFs_ExecuteFileAccess or criFs_ExecuteDataDecompression on a separate thread.
<b