geany/geany-plugins — pull request #156 by b4n (2014-10-12 13:13:28+00:00)
Title: debugger: Fix GCond usage

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.

--------------

@cesspit An alternative, simpler implementation would be to simply lock the `m` mutex in `saving_thread_func()` before the loop and re-lock it just after (right before destroying it). However, I don't see why there would be need for two different mutexes here, as since `g_cond_timed_wait()` unlocks the passed in mutex it makes it works just like what this loop needs.

Note that this is an important issue as currently loading the Debugger plugin aborts Geany as a whole under GLib >= 2.42. See for example [Debian bug #763050](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=763050#10).