From: Braden M. <br...@us...> - 2006-12-15 07:39:52
|
Update of /cvsroot/openvrml/openvrml/src/openvrml-gtkplug In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19161/src/openvrml-gtkplug Modified Files: Makefile.am main.cpp Removed Files: flag.cpp flag.h Log Message: Removed quit_flag silliness in openvrml-gtkplug. Made the "producer" thread--command_channel_loop--spawn (and join) the "consumer" thread, command_istream_reader. "quit" is propagated up from the consumer, to the producer, to the main thread. Index: main.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-gtkplug/main.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** main.cpp 4 Dec 2006 05:18:07 -0000 1.7 --- main.cpp 15 Dec 2006 07:39:48 -0000 1.8 *************** *** 37,41 **** # include "command_istream.h" # include "plugin_streambuf.h" - # include "flag.h" using namespace openvrml_player; --- 37,40 ---- *************** *** 53,65 **** // const char initial_stream_uri[] = "x-openvrml-initial:"; - - // - // Used to signal the various threads that we're done. "quit" is - // initiated when the command_istream gets EOF. At that point, the - // command_istream_reader thread sets quit_flag to true. This flag is - // checked by the command_channel_loop thread and the main (rendering) - // thread, signaling them to terminate. - // - flag quit_flag; } --- 52,55 ---- *************** *** 67,72 **** struct command_istream_reader { ! explicit command_istream_reader(command_istream & in): ! in_(&in) {} --- 57,66 ---- struct command_istream_reader { ! command_istream_reader(command_istream & in, ! GtkVrmlBrowser & vrml_browser, ! GMainLoop & command_channel_loop): ! in_(&in), ! vrml_browser_(&vrml_browser), ! command_channel_loop_(&command_channel_loop) {} *************** *** 155,181 **** // ! // Set the quit flag. ! // ! ::quit_flag.value(true); ! ! // ! // We can safely shut down the Gtk main loop from here. ! // ! // (However, trying to shut down the command_main loop results in ! // it deadlocking in g_main_context_check's call to poll. So we ! // still use the annoying quit_flag condition variable (see above) ! // to end that thread). // ! gtk_main_quit(); } private: ! command_istream * in_; }; } - extern "C" gboolean - openvrml_player_command_channel_loop_quit_event(gpointer data); - namespace { --- 149,165 ---- // ! // Tell the command_channel_loop thread to quit. (This is our ! // "producer" thread; it's also the thread that spawned us.) // ! g_main_loop_quit(this->command_channel_loop_); } private: ! command_istream * const in_; ! GtkVrmlBrowser * const vrml_browser_; ! GMainLoop * const command_channel_loop_; }; } namespace { *************** *** 262,282 **** }; - GIOChannel * request_channel; - 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 = --- 246,272 ---- }; struct command_channel_loop { command_channel_loop(GIOChannel & command_channel, ! command_istream & command_in, ! GtkVrmlBrowser & vrml_browser): command_channel_(&command_channel), ! command_in_(&command_in), ! vrml_browser_(&vrml_browser) {} void operator()() const throw () { + using boost::function0; + using boost::scoped_ptr; + using boost::thread; + GMainContext * const main_context = g_main_context_new(); scope_guard main_context_guard = make_guard(g_main_context_unref, main_context); + boost::ignore_unused_variable_warning(main_context_guard); GMainLoop * const main_loop = g_main_loop_new(main_context, false); scope_guard main_loop_guard = make_guard(g_main_loop_unref, main_loop); + boost::ignore_unused_variable_warning(main_loop_guard); GSource * const command_watch = *************** *** 285,288 **** --- 275,279 ---- scope_guard command_watch_guard = make_guard(g_source_unref, command_watch); + boost::ignore_unused_variable_warning(command_watch_guard); static const GDestroyNotify notify = 0; *************** *** 290,309 **** 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); } --- 281,309 ---- 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); ! // ! // The command_istream_reader thread is our "consumer" thread. ! // ! function0<void> read_commands = ! command_istream_reader(*this->command_in_, ! *this->vrml_browser_, ! *main_loop); ! const scoped_ptr<thread> ! command_reader_thread(new thread(read_commands)); g_main_loop_run(main_loop); + + // + // If we're here, our consumer thread is done. Join it and tell + // the GTK+ main loop to quit. + // + command_reader_thread->join(); + + gtk_main_quit(); } *************** *** 311,314 **** --- 311,315 ---- GIOChannel * const command_channel_; command_istream * const command_in_; + GtkVrmlBrowser * const vrml_browser_; }; } *************** *** 371,379 **** command_istream command_in; ! ::request_channel = g_io_channel_unix_new(1); // stdout GtkWidget * const window = gtk_plug_new(socket_id); ! GtkWidget * const vrml_browser = gtk_vrml_browser_new(::request_channel); gtk_container_add(GTK_CONTAINER(window), vrml_browser); --- 372,380 ---- command_istream command_in; ! GIOChannel * const request_channel = g_io_channel_unix_new(1); // stdout GtkWidget * const window = gtk_plug_new(socket_id); ! GtkWidget * const vrml_browser = gtk_vrml_browser_new(request_channel); gtk_container_add(GTK_CONTAINER(window), vrml_browser); *************** *** 382,387 **** thread_group threads; ! GIOChannel * command_channel = 0; ! command_channel = g_io_channel_unix_new(0); // stdin error = 0; GIOStatus status = g_io_channel_set_encoding(command_channel, --- 383,387 ---- thread_group threads; ! GIOChannel * const command_channel = g_io_channel_unix_new(0); // stdin error = 0; GIOStatus status = g_io_channel_set_encoding(command_channel, *************** *** 397,401 **** function0<void> command_channel_loop_func = ! command_channel_loop(*command_channel, command_in); threads.create_thread(command_channel_loop_func); --- 397,403 ---- function0<void> command_channel_loop_func = ! command_channel_loop(*command_channel, ! command_in, ! *GTK_VRML_BROWSER(vrml_browser)); threads.create_thread(command_channel_loop_func); *************** *** 411,417 **** } - function0<void> read_commands = command_istream_reader(command_in); - threads.create_thread(read_commands); - gtk_main(); --- 413,416 ---- *************** *** 427,434 **** g_io_channel_unref(command_channel); ! if (::request_channel) { GError * error = 0; const gboolean flush = false; ! GIOStatus status = g_io_channel_shutdown(::request_channel, flush, &error); --- 426,433 ---- g_io_channel_unref(command_channel); ! if (request_channel) { GError * error = 0; const gboolean flush = false; ! GIOStatus status = g_io_channel_shutdown(request_channel, flush, &error); *************** *** 440,454 **** } } ! g_io_channel_unref(::request_channel); ! } ! ! gboolean openvrml_player_command_channel_loop_quit_event(const gpointer data) ! { ! GMainLoop * const main_loop = static_cast<GMainLoop *>(data); ! ! if (::quit_flag.value()) { ! g_main_loop_quit(main_loop); ! return false; ! } ! return true; } --- 439,442 ---- } } ! g_io_channel_unref(request_channel); } Index: Makefile.am =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-gtkplug/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 2 Oct 2006 03:44:08 -0000 1.3 --- Makefile.am 15 Dec 2006 07:39:48 -0000 1.4 *************** *** 30,41 **** command_istream.h \ plugin_streambuf.h \ ! gtkvrmlbrowser.h \ ! flag.h openvrml_gtkplug_SOURCES = \ main.cpp \ command_istream.cpp \ plugin_streambuf.cpp \ ! gtkvrmlbrowser.cpp \ ! flag.cpp EXTRA_DIST = $(openvrml_gtkplug_SOURCES) --- 30,39 ---- command_istream.h \ plugin_streambuf.h \ ! gtkvrmlbrowser.h openvrml_gtkplug_SOURCES = \ main.cpp \ command_istream.cpp \ plugin_streambuf.cpp \ ! gtkvrmlbrowser.cpp EXTRA_DIST = $(openvrml_gtkplug_SOURCES) --- flag.h DELETED --- --- flag.cpp DELETED --- |