gdk_threads_enter is not reentrant

I have a piece of code which may be run from a GTK callback or within
a thread outside of gtk_main().  The problem is that
gdk_threads_enter() is not reentrant.  It locks up if I call it within
a callback function.  If I omit the lock, I could trash GTK internals.

    MyData::destroy() {
	gdk_threads_enter();   // hangs if called withing a callback
	free_some_gdk_data();  // but I need to lock to protect GTK

Could gdk_threads_enter() be made reentrant?  You should be able to
call it twice from the same thread without deadlock.  How about
something like this?

    pthread_mutex_t gdk_lock_mutex;
    int             gdk_lock_count;
    pthread_t       gdk_lock_thread;

    gdk_threads_enter() {
	if( gdk_lock_thread != pthread_self() ) {
	    assert(gdk_lock_count == 0 && gdk_lock_thread == 0);
	    gdk_lock_thread = pthread_self();

    gdk_threads_leave() {
	assert(gdk_lock_count > 0 && gdk_lock_thread == pthread_self());
	if( gdk_lock_count == 0 ) {
	    gdk_lock_thread = 0;
	    gdk_lock_count = 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]