From: Braden M. <br...@us...> - 2006-12-04 05:18:09
|
Update of /cvsroot/openvrml/openvrml/src/openvrml-gtkplug In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3537/src/openvrml-gtkplug Modified Files: main.cpp Log Message: Call g_thread_init to initialize GLib's thread support for openvrml-gtkplug. Create the GMainLoop for the command reader loop in the command reader thread instead of the main thread. Index: main.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-gtkplug/main.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** main.cpp 2 Dec 2006 07:20:21 -0000 1.6 --- main.cpp 4 Dec 2006 05:18:07 -0000 1.7 *************** *** 22,25 **** --- 22,26 ---- # include <sstream> # include <boost/lexical_cast.hpp> + # include <boost/multi_index/detail/scope_guard.hpp> # include <boost/thread/thread.hpp> # include <unistd.h> *************** *** 39,42 **** --- 40,44 ---- using namespace openvrml_player; + using namespace boost::multi_index::detail; // for scope_guard namespace { *************** *** 263,289 **** struct command_channel_loop { ! explicit command_channel_loop(GMainLoop & main_loop): ! main_loop_(&main_loop) {} void operator()() const throw () { GSource * const quit = g_idle_source_new(); ! const GDestroyNotify notify = 0; g_source_set_callback( quit, ::openvrml_player_command_channel_loop_quit_event, ! this->main_loop_, notify); ! guint source_id = ! g_source_attach(quit, ! g_main_loop_get_context(this->main_loop_)); ! g_return_if_fail(source_id != 0); ! g_main_loop_run(this->main_loop_); } private: ! GMainLoop * main_loop_; }; } --- 265,314 ---- struct command_channel_loop { ! command_channel_loop(GIOChannel & command_channel, ! command_istream & command_in): ! command_channel_(&command_channel), ! command_in_(&command_in) {} void operator()() const throw () { + GMainContext * const main_context = g_main_context_new(); + scope_guard main_context_guard = make_guard(g_main_context_unref, + main_context); + GMainLoop * const main_loop = g_main_loop_new(main_context, false); + scope_guard main_loop_guard = make_guard(g_main_loop_unref, + main_loop); + + GSource * const command_watch = + g_io_create_watch(this->command_channel_, + GIOCondition(G_IO_IN | G_IO_HUP)); + scope_guard command_watch_guard = make_guard(g_source_unref, + command_watch); + + static const GDestroyNotify notify = 0; + g_source_set_callback( + command_watch, + reinterpret_cast<GSourceFunc>(::command_data_available), + static_cast<command_streambuf *>(this->command_in_->rdbuf()), notify); + const guint command_watch_id = g_source_attach(command_watch, + main_context); + g_assert(command_watch_id != 0); + GSource * const quit = g_idle_source_new(); ! scope_guard quit_guard = make_guard(g_source_unref, quit); g_source_set_callback( quit, ::openvrml_player_command_channel_loop_quit_event, ! main_loop, notify); ! const guint quit_source_id = g_source_attach(quit, main_context); ! g_assert(quit_source_id != 0); ! g_main_loop_run(main_loop); } private: ! GIOChannel * const command_channel_; ! command_istream * const command_in_; }; } *************** *** 302,305 **** --- 327,332 ---- using namespace openvrml_player; + g_thread_init(0); + g_set_application_name(application_name); *************** *** 355,365 **** thread_group threads; - GMainContext * command_main_context = 0; - GMainLoop * command_main = 0; GIOChannel * command_channel = 0; - GSource * command_watch = 0; - - command_main_context = g_main_context_new(); - command_main = g_main_loop_new(command_main_context, false); command_channel = g_io_channel_unix_new(0); // stdin error = 0; --- 382,386 ---- *************** *** 375,391 **** } - command_watch = g_io_create_watch(command_channel, - GIOCondition(G_IO_IN | G_IO_HUP)); - const GDestroyNotify notify = 0; - g_source_set_callback( - command_watch, - reinterpret_cast<GSourceFunc>(::command_data_available), - static_cast<command_streambuf *>(command_in.rdbuf()), notify); - guint source_id = g_source_attach(command_watch, - command_main_context); - g_return_val_if_fail(source_id != 0, EXIT_FAILURE); - function0<void> command_channel_loop_func = ! command_channel_loop(*command_main); threads.create_thread(command_channel_loop_func); --- 396,401 ---- } function0<void> command_channel_loop_func = ! command_channel_loop(*command_channel, command_in); threads.create_thread(command_channel_loop_func); *************** *** 408,413 **** threads.join_all(); - g_source_unref(command_watch); - status = g_io_channel_shutdown(command_channel, true, &error); if (status != G_IO_STATUS_NORMAL) { --- 418,421 ---- *************** *** 419,425 **** g_io_channel_unref(command_channel); - g_main_loop_unref(command_main); - g_main_context_unref(command_main_context); - if (::request_channel) { GError * error = 0; --- 427,430 ---- |