From: Braden M. <br...@us...> - 2007-05-15 04:06:12
|
Update of /cvsroot/openvrml/openvrml/src/openvrml-xembed In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28374/src/openvrml-xembed Modified Files: gtkvrmlbrowser.cpp plugin_streambuf.cpp plugin_streambuf.h Log Message: Added a read/write mutex. Hopefully Boost will have a read/write mutex before too long; if/when that happens, this one can probably go away. openvrml::read_write_mutex simply follows the implementation described by Butenhof using the Boost thread primitives. Index: plugin_streambuf.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-xembed/plugin_streambuf.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** plugin_streambuf.cpp 12 May 2007 03:29:41 -0000 1.5 --- plugin_streambuf.cpp 15 May 2007 04:06:11 -0000 1.6 *************** *** 142,146 **** find(const std::string & url) const { ! boost::mutex::scoped_lock lock(this->mutex_); map_t::const_iterator pos = this->map_.find(url); return pos == this->map_.end() --- 142,146 ---- find(const std::string & url) const { ! openvrml::read_write_mutex::scoped_read_lock lock(this->mutex_); map_t::const_iterator pos = this->map_.find(url); return pos == this->map_.end() *************** *** 154,158 **** const boost::shared_ptr<plugin_streambuf> & streambuf) { ! boost::mutex::scoped_lock lock(this->mutex_); this->map_.insert(make_pair(url, streambuf)); } --- 154,158 ---- const boost::shared_ptr<plugin_streambuf> & streambuf) { ! openvrml::read_write_mutex::scoped_write_lock lock(this->mutex_); this->map_.insert(make_pair(url, streambuf)); } *************** *** 171,175 **** erase(const std::string & url) { ! boost::mutex::scoped_lock lock(this->mutex_); const map_t::iterator pos = this->map_.find(url); if (pos == this->map_.end()) { return false; } --- 171,175 ---- erase(const std::string & url) { ! openvrml::read_write_mutex::scoped_write_lock lock(this->mutex_); const map_t::iterator pos = this->map_.find(url); if (pos == this->map_.end()) { return false; } *************** *** 180,184 **** size_t openvrml_xembed::uninitialized_plugin_streambuf_map::size() const { ! boost::mutex::scoped_lock lock(this->mutex_); return this->map_.size(); } --- 180,184 ---- size_t openvrml_xembed::uninitialized_plugin_streambuf_map::size() const { ! openvrml::read_write_mutex::scoped_read_lock lock(this->mutex_); return this->map_.size(); } *************** *** 186,190 **** bool openvrml_xembed::uninitialized_plugin_streambuf_map::empty() const { ! boost::mutex::scoped_lock lock(this->mutex_); return this->map_.empty(); } --- 186,190 ---- bool openvrml_xembed::uninitialized_plugin_streambuf_map::empty() const { ! openvrml::read_write_mutex::scoped_read_lock lock(this->mutex_); return this->map_.empty(); } *************** *** 193,197 **** openvrml_xembed::uninitialized_plugin_streambuf_map::front() const { ! boost::mutex::scoped_lock lock(this->mutex_); g_assert(!this->map_.empty()); return this->map_.begin()->second; --- 193,197 ---- openvrml_xembed::uninitialized_plugin_streambuf_map::front() const { ! openvrml::read_write_mutex::scoped_read_lock lock(this->mutex_); g_assert(!this->map_.empty()); return this->map_.begin()->second; *************** *** 205,209 **** openvrml_xembed::plugin_streambuf_map::find(const size_t id) const { ! boost::mutex::scoped_lock lock(this->mutex_); map_t::const_iterator pos = this->map_.find(id); return pos == this->map_.end() --- 205,209 ---- openvrml_xembed::plugin_streambuf_map::find(const size_t id) const { ! openvrml::read_write_mutex::scoped_read_lock lock(this->mutex_); map_t::const_iterator pos = this->map_.find(id); return pos == this->map_.end() *************** *** 217,221 **** const boost::shared_ptr<plugin_streambuf> & streambuf) { ! boost::mutex::scoped_lock lock(this->mutex_); return this->map_.insert(make_pair(id, streambuf)).second; } --- 217,221 ---- const boost::shared_ptr<plugin_streambuf> & streambuf) { ! openvrml::read_write_mutex::scoped_write_lock lock(this->mutex_); return this->map_.insert(make_pair(id, streambuf)).second; } *************** *** 228,232 **** bool openvrml_xembed::plugin_streambuf_map::erase(const size_t id) { ! boost::mutex::scoped_lock lock(this->mutex_); return this->map_.erase(id) > 0; } --- 228,232 ---- bool openvrml_xembed::plugin_streambuf_map::erase(const size_t id) { ! openvrml::read_write_mutex::scoped_write_lock lock(this->mutex_); return this->map_.erase(id) > 0; } Index: gtkvrmlbrowser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-xembed/gtkvrmlbrowser.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** gtkvrmlbrowser.cpp 27 Apr 2007 03:01:39 -0000 1.8 --- gtkvrmlbrowser.cpp 15 May 2007 04:06:11 -0000 1.9 *************** *** 158,162 **** ::browser_listener browser_listener_; bool browser_initialized_; ! boost::mutex browser_initialized_mutex_; GtkVrmlBrowser & vrml_browser_; guint timer; --- 158,162 ---- ::browser_listener browser_listener_; bool browser_initialized_; ! openvrml::read_write_mutex browser_initialized_mutex_; GtkVrmlBrowser & vrml_browser_; guint timer; *************** *** 212,216 **** { { ! boost::mutex::scoped_lock lock(this->viewer_->browser_initialized_mutex_); this->viewer_->browser_initialized_ = false; --- 212,216 ---- { { ! openvrml::read_write_mutex::scoped_write_lock lock(this->viewer_->browser_initialized_mutex_); this->viewer_->browser_initialized_ = false; *************** *** 246,250 **** GtkGLViewer & viewer = *static_cast<GtkGLViewer *>(vrml_browser->viewer); { ! boost::mutex::scoped_lock lock(viewer.browser_initialized_mutex_); viewer.browser_initialized_ = false; } --- 246,251 ---- GtkGLViewer & viewer = *static_cast<GtkGLViewer *>(vrml_browser->viewer); { ! openvrml::read_write_mutex::scoped_write_lock ! lock(viewer.browser_initialized_mutex_); viewer.browser_initialized_ = false; } *************** *** 348,353 **** GtkGLViewer & viewer = *static_cast<GtkGLViewer *>(GTK_VRML_BROWSER(widget)->viewer); ! boost::mutex::scoped_lock lock(viewer.browser_initialized_mutex_); ! if (!viewer.browser_initialized_) { return true; } if (event->count == 0 --- 349,357 ---- GtkGLViewer & viewer = *static_cast<GtkGLViewer *>(GTK_VRML_BROWSER(widget)->viewer); ! { ! openvrml::read_write_mutex::scoped_read_lock ! lock(viewer.browser_initialized_mutex_); ! if (!viewer.browser_initialized_) { return true; } ! } if (event->count == 0 *************** *** 540,544 **** GtkGLViewer & viewer = *static_cast<GtkGLViewer *>(GTK_VRML_BROWSER(widget)->viewer); ! boost::mutex::scoped_lock lock(viewer.browser_initialized_mutex_); if (!viewer.browser_initialized_) { return true; } viewer.input(&info); --- 544,549 ---- GtkGLViewer & viewer = *static_cast<GtkGLViewer *>(GTK_VRML_BROWSER(widget)->viewer); ! openvrml::read_write_mutex::scoped_read_lock ! lock(viewer.browser_initialized_mutex_); if (!viewer.browser_initialized_) { return true; } viewer.input(&info); *************** *** 677,683 **** { if (event.id() == openvrml::browser_event::initialized) { ! using boost::mutex; ! mutex::scoped_lock lock(this->viewer_.browser_initialized_mutex_); ! this->viewer_.browser_initialized_ = true; gdk_threads_enter(); scope_guard gdk_threads_guard = make_guard(gdk_threads_leave); --- 682,690 ---- { if (event.id() == openvrml::browser_event::initialized) { ! { ! openvrml::read_write_mutex::scoped_write_lock ! lock(this->viewer_.browser_initialized_mutex_); ! this->viewer_.browser_initialized_ = true; ! } gdk_threads_enter(); scope_guard gdk_threads_guard = make_guard(gdk_threads_leave); Index: plugin_streambuf.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-xembed/plugin_streambuf.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** plugin_streambuf.h 12 May 2007 03:29:41 -0000 1.4 --- plugin_streambuf.h 15 May 2007 04:06:11 -0000 1.5 *************** *** 28,31 **** --- 28,32 ---- # include <boost/shared_ptr.hpp> # include <boost/enable_shared_from_this.hpp> + # include <openvrml/read_write_mutex.h> # include "bounded_buffer.h" *************** *** 68,72 **** extern class uninitialized_plugin_streambuf_map : boost::noncopyable { ! mutable boost::mutex mutex_; typedef std::multimap<std::string, boost::shared_ptr<plugin_streambuf> > map_t; --- 69,73 ---- extern class uninitialized_plugin_streambuf_map : boost::noncopyable { ! mutable openvrml::read_write_mutex mutex_; typedef std::multimap<std::string, boost::shared_ptr<plugin_streambuf> > map_t; *************** *** 85,89 **** extern class plugin_streambuf_map : boost::noncopyable { ! mutable boost::mutex mutex_; typedef std::map<size_t, boost::shared_ptr<plugin_streambuf> > map_t; map_t map_; --- 86,90 ---- extern class plugin_streambuf_map : boost::noncopyable { ! mutable openvrml::read_write_mutex mutex_; typedef std::map<size_t, boost::shared_ptr<plugin_streambuf> > map_t; map_t map_; |