From: Braden M. <br...@us...> - 2007-05-12 03:29:19
|
Update of /cvsroot/openvrml/openvrml/src/openvrml-xembed In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26475/src/openvrml-xembed Modified Files: Tag: OpenVRML-0_16-BRANCH main.cpp plugin_streambuf.cpp plugin_streambuf.h Log Message: Protect the plugin_streambuf_map with a mutex. Index: plugin_streambuf.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-xembed/plugin_streambuf.cpp,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** plugin_streambuf.cpp 15 Mar 2007 22:41:42 -0000 1.1.2.3 --- plugin_streambuf.cpp 12 May 2007 03:29:18 -0000 1.1.2.4 *************** *** 72,77 **** this->initialized_ = true; const boost::shared_ptr<plugin_streambuf> this_ = shared_from_this(); ! succeeded = plugin_streambuf_map.insert(make_pair(stream_id, this_)) ! .second; g_assert(succeeded); this->streambuf_initialized_or_failed_.notify_all(); --- 72,76 ---- this->initialized_ = true; const boost::shared_ptr<plugin_streambuf> this_ = shared_from_this(); ! succeeded = plugin_streambuf_map_.insert(stream_id, this_); g_assert(succeeded); this->streambuf_initialized_or_failed_.notify_all(); *************** *** 139,146 **** } - - openvrml_xembed::uninitialized_plugin_streambuf_map - openvrml_xembed::uninitialized_plugin_streambuf_map_; - const boost::shared_ptr<openvrml_xembed::plugin_streambuf> openvrml_xembed::uninitialized_plugin_streambuf_map:: --- 138,141 ---- *************** *** 203,206 **** } ! openvrml_xembed::plugin_streambuf_map_t openvrml_xembed::plugin_streambuf_map; --- 198,235 ---- } + openvrml_xembed::uninitialized_plugin_streambuf_map + openvrml_xembed::uninitialized_plugin_streambuf_map_; ! ! const boost::shared_ptr<openvrml_xembed::plugin_streambuf> ! 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() ! ? boost::shared_ptr<plugin_streambuf>() ! : pos->second; ! } ! ! bool ! openvrml_xembed::plugin_streambuf_map:: ! insert(const size_t id, ! const boost::shared_ptr<plugin_streambuf> & streambuf) ! { ! boost::mutex::scoped_lock lock(this->mutex_); ! return this->map_.insert(make_pair(id, streambuf)).second; ! } ! ! /** ! * @brief Erase the entry corresponding to @p id. ! * ! * @return @c true if an entry was removed; @c false otherwise. ! */ ! bool openvrml_xembed::plugin_streambuf_map::erase(const size_t id) ! { ! boost::mutex::scoped_lock lock(this->mutex_); ! return this->map_.erase(id) > 0; ! } ! ! openvrml_xembed::plugin_streambuf_map ! openvrml_xembed::plugin_streambuf_map_; Index: main.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-xembed/main.cpp,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** main.cpp 15 Mar 2007 22:41:42 -0000 1.1.2.5 --- main.cpp 12 May 2007 03:29:18 -0000 1.1.2.6 *************** *** 71,74 **** --- 71,75 ---- string command_line; while (getline(*this->in_, command_line)) { + using boost::shared_ptr; using std::istringstream; *************** *** 77,82 **** command_line_stream >> command; if (command == "get-url-result") { - using boost::shared_ptr; - std::string url; int result; --- 78,81 ---- *************** *** 88,93 **** streambuf->set_get_url_result(result); } else if (command == "new-stream") { - using boost::shared_ptr; - size_t stream_id; std::string type, url; --- 87,90 ---- *************** *** 115,137 **** size_t stream_id; command_line_stream >> stream_id; ! plugin_streambuf_map_t::iterator pos = ! plugin_streambuf_map.find(stream_id); ! if (pos == plugin_streambuf_map.end()) { ! g_warning("Attempt to destroy a nonexistent stream."); continue; } ! pos->second->buf_.set_eof(); ! plugin_streambuf_map.erase(pos); } else if (command == "write") { size_t stream_id, length; command_line_stream >> stream_id >> length; ! plugin_streambuf_map_t::const_iterator pos = ! plugin_streambuf_map.find(stream_id); ! if (pos == plugin_streambuf_map.end()) { g_warning("Attempt to write to a nonexistent stream."); continue; } for (size_t i = 0; i < length; ++i) { ! pos->second->buf_.put(this->in_->get()); } } else if (command == "load-url") { --- 112,135 ---- size_t stream_id; command_line_stream >> stream_id; ! const shared_ptr<plugin_streambuf> streambuf = ! plugin_streambuf_map_.find(stream_id); ! if (!streambuf) { ! g_warning("Attempt to destroy a nonexistent stream " ! "(with stream ID %lu).", stream_id); continue; } ! streambuf->buf_.set_eof(); ! plugin_streambuf_map_.erase(stream_id); } else if (command == "write") { size_t stream_id, length; command_line_stream >> stream_id >> length; ! const shared_ptr<plugin_streambuf> streambuf = ! plugin_streambuf_map_.find(stream_id); ! if (!streambuf) { g_warning("Attempt to write to a nonexistent stream."); continue; } for (size_t i = 0; i < length; ++i) { ! streambuf->buf_.put(this->in_->get()); } } else if (command == "load-url") { Index: plugin_streambuf.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-xembed/plugin_streambuf.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** plugin_streambuf.h 12 Feb 2007 02:19:13 -0000 1.1.2.2 --- plugin_streambuf.h 12 May 2007 03:29:18 -0000 1.1.2.3 *************** *** 25,28 **** --- 25,29 ---- # include <set> # include <streambuf> + # include <boost/noncopyable.hpp> # include <boost/shared_ptr.hpp> # include <boost/enable_shared_from_this.hpp> *************** *** 66,70 **** }; ! extern class uninitialized_plugin_streambuf_map { mutable boost::mutex mutex_; typedef std::multimap<std::string, boost::shared_ptr<plugin_streambuf> > --- 67,71 ---- }; ! extern class uninitialized_plugin_streambuf_map : boost::noncopyable { mutable boost::mutex mutex_; typedef std::multimap<std::string, boost::shared_ptr<plugin_streambuf> > *************** *** 83,91 **** } uninitialized_plugin_streambuf_map_; ! typedef std::map<size_t, boost::shared_ptr<plugin_streambuf> > ! plugin_streambuf_map_t; ! ! extern plugin_streambuf_map_t plugin_streambuf_map; } --- 84,98 ---- } uninitialized_plugin_streambuf_map_; + 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_; ! public: ! const boost::shared_ptr<plugin_streambuf> find(size_t id) const; ! bool insert(size_t id, ! const boost::shared_ptr<plugin_streambuf> & streambuf); ! bool erase(size_t id); ! } plugin_streambuf_map_; } |