Skip to content

Commit

Permalink
debugger: Fix GCond usage
Browse files Browse the repository at this point in the history
g_cond_wait() and the likes unlock the passed in mutex during the wait
and re-lock it before returning.  However, the code here used to pass
in an unlocked mutex.

This used to work because GLib threading implementation was tolerant
and allowed unlocking an unlocked mutex, but GLib 2.42 has a new and
less tolerant implementation that would abort in such situation.

Fix this by properly locking the passed in mutex.

The implementation here also removes the second mutex only used for the
condition as the one used to protect the loop body can very well be
used and actually makes sense as they protect the same thing.

Doing so requires to properly wait for the thread to quit before
destroying the mutex, but this probably should be done anyways to avoid
forcefully killing the thread when the application quits.
  • Loading branch information
b4n committed Oct 12, 2014
1 parent 83bfbc1 commit 21f9e79
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions debugger/src/dconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,9 @@ static void save_to_keyfile(GKeyFile *keyfile)
static gpointer saving_thread_func(gpointer data)
{
GTimeVal interval;
GMutex *m = g_mutex_new();
g_mutex_lock(change_config_mutex);
do
{
g_mutex_lock(change_config_mutex);

if (
panel_config_changed ||
(debug_config_changed && DEBUG_STORE_PLUGIN == dstore)
Expand Down Expand Up @@ -309,14 +307,12 @@ static gpointer saving_thread_func(gpointer data)

debug_config_changed = FALSE;
}

g_mutex_unlock(change_config_mutex);

g_get_current_time(&interval);
g_time_val_add(&interval, SAVING_INTERVAL);
}
while (!g_cond_timed_wait(cond, m, &interval));
g_mutex_free(m);
while (!g_cond_timed_wait(cond, change_config_mutex, &interval));
g_mutex_unlock(change_config_mutex);

return NULL;
}
Expand Down Expand Up @@ -471,7 +467,7 @@ void config_init(void)
void config_destroy(void)
{
g_cond_signal(cond);
/* ??? g_thread_join(saving_thread); */
g_thread_join(saving_thread);

g_mutex_free(change_config_mutex);
g_cond_free(cond);
Expand Down

0 comments on commit 21f9e79

Please sign in to comment.