- Code: Select all
cef_main_args_t main_args = {argc, argv};
cef_settings_t settings = {0};
guac_http_cef_app_t* app = guac_http_cef_app_init();
cef_initialize(&main_args, &settings, (cef_app_t *)app, NULL);
/* Start the CEF event loop to handle CEF-related actions and rendering */
cef_run_message_loop();
Description for the cef_run_message_loop function:
Run the CEF message loop. Use this function instead of an application-
provided message loop to get the best balance between performance and CPU
usage. This function should only be called on the main application thread
and only if cef_initialize() is called with a
cef_settings_t.multi_threaded_message_loop value of false (0). This function
will block until a quit message is received by the system.
The cef_run_message_loop just blocks indefinitely until we call the quit function cef_quit_message_loop
Quit the CEF message loop that was started by calling
cef_run_message_loop(). This function should only be called on the main
application thread and only if cef_run_message_loop() was used.
Now I can't figure out how it expects me to call a the cef_quit_message_loop if cef_run_message_loop is blocking. I tried making a separate thread that starts before cef_run_message_loop, waits for a flag indicating we need to shut down CEF, but it just prints an error -1 (really helpful).
- Code: Select all
static void* guac_http_cef_termination_thread(void* data) {
guac_http_cef_shm_event_thread_data_t* thread_data = (guac_http_cef_shm_event_thread_data_t*) data;
shm_memory* shm = thread_data->shm;
/* Locking the mutex to prevent race condition while modifying the termination flag. */
pthread_mutex_lock(&shm->data->termination_mutex);
/* Waiting for the CEF process to update termination flag indicating it has completed termination. */
while (shm->data->termination_flag != TERMINATION_START) {
pthread_cond_wait(&shm->data->cond_termination_flag_updated, &shm->data->termination_mutex);
}
/* Release the mutex post-termination */
pthread_mutex_unlock(&shm->data->termination_mutex);
cef_quit_message_loop();
cef_shutdown();
return NULL;
}
From what I have read online it's because I am calling cef_quit_message_loop in a separate thread instead of the same place that cef_run_message_loop is called.
After doing some reading I decided to try calling cef_do_message_loop_work and to use this I add the following function to my browser_process_handler
- Code: Select all
static void on_schedule_message_pump_work(struct _cef_browser_process_handler_t* self,
int64 delay_ms) {
if (delay_ms > 0)
sleep(delay_ms);
cef_do_message_loop_work();
}
And now I just wait for a termination request and call chutdown within the same thread as cef is initialized.
- Code: Select all
cef_main_args_t main_args = {argc, argv};
cef_settings_t settings = {0};
guac_http_cef_app_t* app = guac_http_cef_app_init();
cef_initialize(&main_args, &settings, (cef_app_t *)app, NULL);
/* Start the CEF event loop to handle CEF-related actions and rendering */
cef_run_message_loop();
/* Locking the mutex to prevent race condition while modifying the termination flag. */
pthread_mutex_lock(&shm->data->termination_mutex);
/* Waiting for the CEF process to update termination flag indicating it has completed termination. */
while (shm->data->termination_flag != TERMINATION_START) {
pthread_cond_wait(&shm->data->cond_termination_flag_updated, &shm->data->termination_mutex);
}
/* Shutdown and clean up resources after CEF has been terminated */
cef_shutdown();
However I am still seeing the Error: -1 and cef is not shutting down. Is there something that I am missing? Thanks