[gparted/psusi/refactor: 1/16] Remove gdk_threads_enter/exit
- From: Phillip Susi <psusi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted/psusi/refactor: 1/16] Remove gdk_threads_enter/exit
- Date: Tue, 29 Jan 2013 03:45:29 +0000 (UTC)
commit 6ecfe31942aa884d4c120795336a61dd0952753a
Author: Phillip Susi <psusi ubuntu com>
Date: Mon Jan 14 20:57:34 2013 -0500
Remove gdk_threads_enter/exit
Use of these functions is depreciated and making gtk calls in a background
thread still sometimes causes deadlocks or crashes. Change ped exception
handler to instead use an idle function to force the main thread to display
the dialog box.
src/Dialog_Progress.cc | 2 -
src/GParted_Core.cc | 56 +++++++++++++++++++++++++++++++++--------------
src/Win_GParted.cc | 2 -
src/main.cc | 2 -
4 files changed, 39 insertions(+), 23 deletions(-)
---
diff --git a/src/Dialog_Progress.cc b/src/Dialog_Progress.cc
index 253a378..dd314e8 100644
--- a/src/Dialog_Progress.cc
+++ b/src/Dialog_Progress.cc
@@ -221,9 +221,7 @@ void Dialog_Progress::on_signal_show()
while ( Gtk::Main::events_pending() )
Gtk::Main::iteration();
- gdk_threads_leave();
usleep( 100000 ) ;
- gdk_threads_enter();
}
//set status (succes/error) for this operation
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 7a4dd86..1f0bcc0 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3539,32 +3539,54 @@ public:
}
};
-PedExceptionOption GParted_Core::ped_exception_handler( PedException * e )
+struct ped_exception_ctx {
+ PedExceptionOption ret;
+ PedException *e;
+ Glib::Threads::Mutex mutex;
+ Glib::Threads::Cond cond;
+};
+
+static bool _ped_exception_handler( struct ped_exception_ctx *ctx )
{
- PedExceptionOption ret = PED_EXCEPTION_UNHANDLED;
- std::cout << e ->message << std::endl ;
+ std::cout << ctx->e->message << std::endl;
- libparted_messages .push_back( e->message ) ;
+ libparted_messages.push_back( ctx->e->message );
char optcount = 0;
int opt = 0;
for( char c = 0; c < 10; c++ )
- if( e->options & (1 << c) ) {
+ if( ctx->e->options & (1 << c) ) {
opt = (1 << c);
optcount++;
}
// if only one option was given, choose it without popup
- if( optcount == 1 && e->type != PED_EXCEPTION_BUG && e->type != PED_EXCEPTION_FATAL )
- return (PedExceptionOption)opt;
- if (Glib::Thread::self() != GParted_Core::mainthread)
- gdk_threads_enter();
- PedExceptionMsg msg( *e );
+ if( optcount == 1 && ctx->e->type != PED_EXCEPTION_BUG && ctx->e->type != PED_EXCEPTION_FATAL )
+ {
+ ctx->ret = (PedExceptionOption)opt;
+ ctx->cond.signal();
+ return false;
+ }
+ PedExceptionMsg msg( *ctx->e );
msg.show_all();
- ret = (PedExceptionOption)msg.run();
- if (Glib::Thread::self() != GParted_Core::mainthread)
- gdk_threads_leave();
- if (ret < 0)
- ret = PED_EXCEPTION_UNHANDLED;
- return ret;
+ ctx->ret = (PedExceptionOption)msg.run();
+ if (ctx->ret < 0)
+ ctx->ret = PED_EXCEPTION_UNHANDLED;
+ ctx->mutex.lock();
+ ctx->cond.signal();
+ ctx->mutex.unlock();
+ return false;
+}
+
+PedExceptionOption GParted_Core::ped_exception_handler( PedException * e )
+{
+ struct ped_exception_ctx ctx;
+ ctx.ret = PED_EXCEPTION_UNHANDLED;
+ ctx.e = e;
+ if (Glib::Thread::self() != GParted_Core::mainthread) {
+ ctx.mutex.lock();
+ g_idle_add( (GSourceFunc)_ped_exception_handler, &ctx );
+ ctx.cond.wait( ctx.mutex );
+ } else _ped_exception_handler( &ctx );
+ return ctx.ret;
}
GParted_Core::~GParted_Core()
@@ -3572,5 +3594,5 @@ GParted_Core::~GParted_Core()
}
Glib::Thread *GParted_Core::mainthread;
-
+
} //GParted
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 98145f2..c26f7f9 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -627,9 +627,7 @@ void Win_GParted::show_pulsebar( const Glib::ustring & status_message )
pulsebar .pulse();
while ( Gtk::Main::events_pending() )
Gtk::Main::iteration();
- gdk_threads_leave();
usleep( 100000 );
- gdk_threads_enter();
Glib::ustring tmp_msg = gparted_core .get_thread_status_message() ;
if ( tmp_msg != "" )
statusbar .push( tmp_msg ) ;
diff --git a/src/main.cc b/src/main.cc
index 02118d3..7f611fc 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -25,8 +25,6 @@ int main( int argc, char *argv[] )
{
//initialize thread system
Glib::thread_init() ;
- gdk_threads_init();
- gdk_threads_enter();
GParted::GParted_Core::mainthread = Glib::Thread::self();
Gtk::Main kit( argc, argv ) ;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]