From: Braden M. <br...@us...> - 2006-08-03 23:10:29
|
Update of /cvsroot/openvrml/openvrml/mozilla-plugin/src/openvrml-player In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25486/mozilla-plugin/src/openvrml-player Modified Files: bounded_buffer.h command_istream.cpp Log Message: Changed bounded_buffer to allow setting EOF. Index: command_istream.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/mozilla-plugin/src/openvrml-player/command_istream.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** command_istream.cpp 8 Jul 2006 07:00:34 -0000 1.4 --- command_istream.cpp 3 Aug 2006 23:10:25 -0000 1.5 *************** *** 19,26 **** // # include <cerrno> # include "command_istream.h" ! openvrml_player::command_streambuf::command_streambuf() { this->setg(&this->c_, &this->c_, &this->c_); --- 19,28 ---- // + # include <cassert> # include <cerrno> # include "command_istream.h" ! openvrml_player::command_streambuf::command_streambuf(): ! c_('\0') { this->setg(&this->c_, &this->c_, &this->c_); *************** *** 30,38 **** openvrml_player::command_streambuf::underflow() { ! int_type c = traits_type::to_int_type(this->source_buffer_.get()); ! if (c == traits_type::eof()) { return traits_type::eof(); } ! this->c_ = traits_type::to_char_type(c); this->setg(&this->c_, &this->c_, &this->c_ + 1); ! return traits_type::to_int_type(*this->gptr()); } --- 32,42 ---- openvrml_player::command_streambuf::underflow() { ! const int_type i = this->source_buffer_.get(); ! if (traits_type::eq_int_type(i, traits_type::eof())) { ! return traits_type::eof(); ! } ! this->c_ = traits_type::to_char_type(i); this->setg(&this->c_, &this->c_, &this->c_ + 1); ! return i; } *************** *** 67,71 **** } if (status == G_IO_STATUS_EOF) { ! streambuf.source_buffer_.put(traits_type::eof()); return false; } --- 71,75 ---- } if (status == G_IO_STATUS_EOF) { ! streambuf.source_buffer_.set_eof(); return false; } Index: bounded_buffer.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/mozilla-plugin/src/openvrml-player/bounded_buffer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bounded_buffer.h 9 Jan 2006 00:21:09 -0000 1.1 --- bounded_buffer.h 3 Aug 2006 23:10:24 -0000 1.2 *************** *** 22,25 **** --- 22,26 ---- # define OPENVRML_PLAYER_BOUNDED_BUFFER_H + # include <string> # include <boost/thread/mutex.hpp> # include <boost/thread/condition.hpp> *************** *** 27,54 **** namespace openvrml_player { ! template <typename T, size_t BufferSize> class bounded_buffer { mutable boost::mutex mutex_; ! boost::condition buffer_not_full_, buffer_not_empty_; ! T buf_[BufferSize]; size_t begin_, end_, buffered_; public: bounded_buffer(); ! void put(const T & c); ! const T get(); size_t buffered() const; }; ! template <typename T, size_t BufferSize> ! bounded_buffer<T, BufferSize>::bounded_buffer(): begin_(0), end_(0), ! buffered_(0) {} ! template <typename T, size_t BufferSize> ! void bounded_buffer<T, BufferSize>::put(const T & c) { boost::mutex::scoped_lock lock(this->mutex_); --- 28,63 ---- namespace openvrml_player { ! template <typename CharT, size_t BufferSize> class bounded_buffer { mutable boost::mutex mutex_; ! boost::condition buffer_not_full_, buffer_not_empty_or_eof_; ! CharT buf_[BufferSize]; size_t begin_, end_, buffered_; + bool eof_; public: + typedef CharT char_type; + typedef typename std::char_traits<char_type> traits_type; + typedef typename traits_type::int_type int_type; + bounded_buffer(); ! void put(const char_type & c); ! int_type get(); size_t buffered() const; + void set_eof(); + bool eof() const; }; ! template <typename CharT, size_t BufferSize> ! bounded_buffer<CharT, BufferSize>::bounded_buffer(): begin_(0), end_(0), ! buffered_(0), ! eof_(false) {} ! template <typename CharT, size_t BufferSize> ! void bounded_buffer<CharT, BufferSize>::put(const char_type & c) { boost::mutex::scoped_lock lock(this->mutex_); *************** *** 59,85 **** this->end_ = (this->end_ + 1) % BufferSize; ++this->buffered_; ! this->buffer_not_empty_.notify_one(); } ! template <typename T, size_t BufferSize> ! const T bounded_buffer<T, BufferSize>::get() { boost::mutex::scoped_lock lock(this->mutex_); ! while (this->buffered_ == 0) { ! this->buffer_not_empty_.wait(lock); } ! T c = this->buf_[this->begin_]; this->begin_ = (this->begin_ + 1) % BufferSize; --this->buffered_; this->buffer_not_full_.notify_one(); return c; } ! template <typename T, size_t BufferSize> ! size_t bounded_buffer<T, BufferSize>::buffered() const { boost::mutex::scoped_lock lock(this->mutex_); return this->buffered_; } } --- 68,114 ---- this->end_ = (this->end_ + 1) % BufferSize; ++this->buffered_; ! this->buffer_not_empty_or_eof_.notify_one(); } ! template <typename CharT, size_t BufferSize> ! typename bounded_buffer<CharT, BufferSize>::int_type ! bounded_buffer<CharT, BufferSize>::get() { boost::mutex::scoped_lock lock(this->mutex_); ! while (this->buffered_ == 0 && !this->eof_) { ! this->buffer_not_empty_or_eof_.wait(lock); } ! if (this->buffered_ == 0 && this->eof_) { ! return traits_type::eof(); ! } ! const int_type c = traits_type::to_int_type(this->buf_[this->begin_]); this->begin_ = (this->begin_ + 1) % BufferSize; --this->buffered_; this->buffer_not_full_.notify_one(); + assert(!traits_type::eq_int_type(c, traits_type::eof())); return c; } ! template <typename CharT, size_t BufferSize> ! size_t bounded_buffer<CharT, BufferSize>::buffered() const { boost::mutex::scoped_lock lock(this->mutex_); return this->buffered_; } + + template <typename CharT, size_t BufferSize> + void bounded_buffer<CharT, BufferSize>::set_eof() + { + boost::mutex::scoped_lock lock(this->mutex_); + this->eof_ = true; + this->buffer_not_empty_or_eof_.notify_one(); + } + + template <typename CharT, size_t BufferSize> + bool bounded_buffer<CharT, BufferSize>::eof() const + { + boost::mutex::scoped_lock lock(this->mutex_); + return this->eof_; + } } |