37 g_mutex_lock (&watchdog->
lock);
38 g_cond_signal (&watchdog->
cond);
39 g_mutex_unlock (&watchdog->
lock);
41 return G_SOURCE_REMOVE;
53 g_main_context_push_thread_default (watchdog->
context);
55 idle_source = g_idle_source_new ();
56 g_source_set_callback (idle_source,
58 g_source_attach (idle_source, watchdog->
context);
59 g_source_unref (idle_source);
61 g_main_loop_run (watchdog->
loop);
63 g_main_context_pop_thread_default (watchdog->
context);
80 ml_loge (
"Invalid parameter: watchdog handle is NULL.");
86 ml_loge (
"Failed to allocate memory for watchdog.");
90 watchdog->
context = g_main_context_new ();
93 g_mutex_init (&watchdog->
lock);
94 g_cond_init (&watchdog->
cond);
95 g_mutex_lock (&watchdog->
lock);
101 ml_loge (
"Failed to create watchdog thread: %s", error->message);
102 g_clear_error (&error);
107 end_time = g_get_monotonic_time () + 5 * G_TIME_SPAN_SECOND;
108 while (!g_main_loop_is_running (watchdog->
loop)) {
109 if (!g_cond_wait_until (&watchdog->
cond, &watchdog->
lock, end_time)) {
110 ml_loge (
"Failed to wait main loop running.");
117 g_mutex_unlock (&watchdog->
lock);
118 g_mutex_clear (&watchdog->
lock);
119 g_cond_clear (&watchdog->
cond);
124 *watchdog_h = watchdog;
138 if (watchdog && watchdog->
context) {
139 g_main_loop_quit (watchdog->
loop);
140 g_thread_join (watchdog->
thread);
143 g_main_loop_unref (watchdog->
loop);
144 watchdog->
loop = NULL;
146 g_main_context_unref (watchdog->
context);
160 if (watchdog && watchdog->
source) {
161 g_source_destroy (watchdog->
source);
162 g_source_unref (watchdog->
source);
172 guint interval,
void *user_data)
176 if (!watchdog || !func) {
177 ml_loge (
"Invalid parameter: watchdog handle or func is NULL.");
182 watchdog->
source = g_timeout_source_new (interval);
183 g_source_set_callback (watchdog->
source, func, user_data, NULL);
187 (
"Failed to feed to watchdog. Watchdog is not created or context is invalid.");