gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/parser/Makefile.am serve...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/parser/Makefile.am serve...
Date: Thu, 30 Nov 2006 13:25:42 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  06/11/30 13:25:42

Modified files:
        .              : ChangeLog 
        server/parser  : Makefile.am movie_def_impl.cpp movie_def_impl.h 

Log message:
                * server/parser/Makefile.am: added BOOST_LIBS as
                  we now use boost threads.
                * server/parser/movie_def_impl.{h,cpp}: be less
                  lock-intensive in load. Note that this exposes
                  a problem with get_bytes_loaded, play elvis.swf
                  to see. I'm committing anyway as a mileston,
                  will fix get_bytes_loaded later.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1826&r2=1.1827
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/Makefile.am?cvsroot=gnash&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/movie_def_impl.cpp?cvsroot=gnash&r1=1.49&r2=1.50
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/movie_def_impl.h?cvsroot=gnash&r1=1.23&r2=1.24

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1826
retrieving revision 1.1827
diff -u -b -r1.1826 -r1.1827
--- ChangeLog   30 Nov 2006 00:13:27 -0000      1.1826
+++ ChangeLog   30 Nov 2006 13:25:42 -0000      1.1827
@@ -1,5 +1,15 @@
 2006-11-30 Sandro Santilli <address@hidden>
 
+       * server/parser/Makefile.am: added BOOST_LIBS as
+         we now use boost threads.
+       * server/parser/movie_def_impl.{h,cpp}: be less
+         lock-intensive in load. Note that this exposes
+         a problem with get_bytes_loaded, play elvis.swf
+         to see. I'm committing anyway as a mileston,
+         will fix get_bytes_loaded later.
+
+2006-11-30 Sandro Santilli <address@hidden>
+
        * testsuite/actionscript.all/gen-index-wiki.sh:
          include a link to the source code.
        * server/parser/movie_def_impl.cpp (read_all_swf):

Index: server/parser/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/parser/Makefile.am,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- server/parser/Makefile.am   28 Nov 2006 12:10:27 -0000      1.18
+++ server/parser/Makefile.am   30 Nov 2006 13:25:42 -0000      1.19
@@ -18,7 +18,7 @@
 # 
 #
 
-# $Id: Makefile.am,v 1.18 2006/11/28 12:10:27 strk Exp $
+# $Id: Makefile.am,v 1.19 2006/11/30 13:25:42 strk Exp $
 
 AUTOMAKE_OPTIONS = 
 
@@ -71,7 +71,10 @@
 
 libgnashparser_la_LIBADD = \
        $(top_builddir)/libbase/libgnashbase.la 
-libgnashparser_la_LDFLAGS = -avoid-version
+
+libgnashparser_la_LDFLAGS = \
+       -avoid-version \
+       $(BOOST_LIBS)
 
 # Rebuild with GCC 4.x Mudflap support
 mudflap:

Index: server/parser/movie_def_impl.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/parser/movie_def_impl.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- server/parser/movie_def_impl.cpp    29 Nov 2006 23:54:05 -0000      1.49
+++ server/parser/movie_def_impl.cpp    30 Nov 2006 13:25:42 -0000      1.50
@@ -69,14 +69,12 @@
 
 MovieLoader::MovieLoader(movie_def_impl& md)
        :
-       _waiting_for_frame(0),
        _movie_def(md)
 #ifndef WIN32
        ,_thread(0)
 #endif
 {
 #ifdef LOAD_MOVIES_IN_A_SEPARATE_THREAD
-       pthread_cond_init(&_frame_reached_condition, NULL);
        pthread_mutex_init(&_mutex, NULL);
 #endif
 
@@ -88,11 +86,6 @@
 MovieLoader::~MovieLoader()
 {
 #ifdef LOAD_MOVIES_IN_A_SEPARATE_THREAD
-       if ( pthread_cond_destroy(&_frame_reached_condition) != 0 )
-       {
-               log_error("Error destroying MovieLoader condition");
-       }
-
        if ( pthread_mutex_destroy(&_mutex) != 0 )
        {
                log_error("Error destroying MovieLoader mutex");
@@ -152,102 +145,6 @@
        return true;
 }
 
-inline void
-MovieLoader::signal_frame_loaded(size_t frameno)
-{
-#ifndef LOAD_MOVIES_IN_A_SEPARATE_THREAD
-       return; 
-#endif
-       if (_waiting_for_frame &&
-               frameno >= _waiting_for_frame )
-       {
-               pthread_cond_signal(&_frame_reached_condition);
-       }
-}
-
-inline void
-MovieLoader::lock()
-{
-#ifndef LOAD_MOVIES_IN_A_SEPARATE_THREAD
-       return; // nothing to do as there's no mutex
-#endif
-
-#ifdef DEBUG_THREADS_LOCKING
-       // debugging
-       if ( pthread_equal(pthread_self(), _thread) ) {
-               log_msg("MovieLoader locking itself");
-       } else {
-               log_msg("MovieLoader being locked by another thread");
-       }
-#endif
-
-       if ( pthread_mutex_lock(&_mutex) != 0 )
-       {
-               log_error("Error locking MovieLoader");
-       }
-
-#ifdef DEBUG_THREADS_LOCKING
-       // debugging
-       if ( pthread_equal(pthread_self(), _thread) ) {
-               log_msg("MovieLoader locked by itself");
-       } else {
-               log_msg("MovieLoader locked by another thread");
-       }
-#endif
-}
-
-inline void
-MovieLoader::unlock()
-{
-#ifndef LOAD_MOVIES_IN_A_SEPARATE_THREAD
-       return;
-#endif
-
-#ifdef DEBUG_THREADS_LOCKING
-       // debugging
-       if ( pthread_equal(pthread_self(), _thread) ) {
-               log_msg("MovieLoader unlocking itself");
-       } else {
-               log_msg("MovieLoader being unlocked by another thread");
-       }
-#endif
-
-       if ( pthread_mutex_unlock(&_mutex) != 0 )
-       {
-               log_error("Error unlocking MovieLoader");
-       }
-
-#ifdef DEBUG_THREADS_LOCKING
-       // debugging
-       if ( pthread_equal(pthread_self(), _thread) ) {
-               log_msg("MovieLoader unlocked itself");
-       } else {
-               log_msg("MovieLoader unlocked by another thread");
-       }
-#endif
-}
-
-void
-MovieLoader::wait_for_frame(size_t framenum)
-{
-#ifndef LOAD_MOVIES_IN_A_SEPARATE_THREAD
-       assert(0); // don't call wait_for_frame !
-#endif
-
-       // lock the loader so we can rely on m_loading_frame
-       lock();
-
-       if ( _movie_def.get_loading_frame() < framenum )
-       {
-               assert(_waiting_for_frame == 0);
-               _waiting_for_frame = framenum;
-               pthread_cond_wait(&_frame_reached_condition, &_mutex);
-               _waiting_for_frame = 0;
-       }
-
-       unlock();
-}
-
 //
 // some utility stuff
 //
@@ -320,7 +217,10 @@
        m_frame_rate(30.0f),
        m_frame_count(0u),
        m_version(0),
-       m_loading_frame(0u),
+       _frames_loaded(0u),
+       _frames_loaded_mutex(),
+       _frame_reached_condition(),
+       _waiting_for_frame(0),
        m_jpeg_in(0),
        _loader(*this)
 {
@@ -664,16 +564,22 @@
 bool
 movie_def_impl::ensure_frame_loaded(size_t framenum)
 {
-#ifdef LOAD_MOVIES_IN_A_SEPARATE_THREAD 
-        //log_msg("Waiting for frame %u to be loaded", framenum);
-       _loader.wait_for_frame(framenum);
-        //log_msg("Condition reached (m_loading_frame=%u)", m_loading_frame);
-#else
-       assert ( framenum <= m_loading_frame );
+#ifndef LOAD_MOVIES_IN_A_SEPARATE_THREAD 
+       assert ( framenum <= _frames_loaded );
 #endif
 
+       boost::mutex::scoped_lock lock(_frames_loaded_mutex);
+
+       if ( framenum <= _frames_loaded ) return true;
+
+       _waiting_for_frame = framenum;
+        //log_msg("Waiting for frame %u to be loaded", framenum);
 
        // TODO: return false on timeout 
+       _frame_reached_condition.wait(lock);
+
+        //log_msg("Condition reached (_frames_loaded=%u)", _frames_loaded);
+
        return true;
 }
 
@@ -943,9 +849,6 @@
        //size_t it=0;
        while ( (uint32_t) str.get_position() < _swf_end_pos )
        {
-               // Get exclusive lock on loader, to avoid
-               // race conditions with wait_for_frame
-               _loader.lock();
        
                //log_msg("Loading thread iteration %u", it++);
 
@@ -967,15 +870,8 @@
                                log_parse("  show_frame\n");
                        );
 
-                       ++m_loading_frame;
+                       incrementLoadedFrames();
 
-                       // signal load of frame
-                       _loader.signal_frame_loaded(m_loading_frame);
-
-#ifdef DEBUG_FRAMES_LOAD
-                       log_msg("Loaded frame %u/%u",
-                               m_loading_frame, m_frame_count);
-#endif
                }
                else if (_tag_loaders.get(tag_type, &lf))
                 {
@@ -1004,11 +900,9 @@
                                log_warning("hit stream-end tag, "
                                        "but not at the advertised SWF end; "
                                        "stopping for safety.");
-                               _loader.unlock();
                                break;
                        }
                }
-               _loader.unlock();
        }
 
        } catch (const std::exception& e) {
@@ -1023,6 +917,36 @@
 
 }
 
+size_t
+movie_def_impl::get_loading_frame() const
+{
+       boost::mutex::scoped_lock lock(_frames_loaded_mutex);
+       return _frames_loaded;
+}
+
+void
+movie_def_impl::incrementLoadedFrames()
+{
+       boost::mutex::scoped_lock lock(_frames_loaded_mutex);
+
+       ++_frames_loaded;
+
+#ifdef DEBUG_FRAMES_LOAD
+       log_msg("Loaded frame %u/%u",
+               _frames_loaded, m_frame_count);
+#endif
+
+       // signal load of frame if anyone requested it
+       // FIXME: _waiting_form_frame needs mutex ?
+       if (_waiting_for_frame && _frames_loaded >= _waiting_for_frame )
+       {
+               // or should we notify_one ?
+               // See: http://boost.org/doc/html/condition.html
+               _frame_reached_condition.notify_all();
+       }
+
+}
+
 void
 movie_def_impl::export_resource(const tu_string& symbol, resource* res)
 {
@@ -1045,23 +969,6 @@
        // Don't call get_exported_resource() from this movie loader
        assert( ! _loader.isSelfThread() );
 
-       // this is a simple utility so we don't forget
-       // to release our locks...
-       struct scoped_loader_locker {
-               MovieLoader& _loader;
-               scoped_loader_locker(MovieLoader& loader)
-                       :
-                       _loader(loader)
-               {
-                       _loader.lock();
-               }
-               ~scoped_loader_locker()
-               {
-                       _loader.unlock();
-               }
-       };
-
-
        // Keep trying until either we found the export or
        // the stream is over, or there is NO frames progress
        // after def_timeout microseconds.
@@ -1090,7 +997,6 @@
                        return res;
                }
 
-               // FIXME: make get_loading_frame() thread-safe
                size_t new_loading_frame = get_loading_frame();
 
                if ( new_loading_frame != loading_frame )

Index: server/parser/movie_def_impl.h
===================================================================
RCS file: /sources/gnash/gnash/server/parser/movie_def_impl.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- server/parser/movie_def_impl.h      28 Nov 2006 12:30:43 -0000      1.23
+++ server/parser/movie_def_impl.h      30 Nov 2006 13:25:42 -0000      1.24
@@ -36,6 +36,8 @@
 #include <map> // for CharacterDictionary
 #include <string>
 #include <memory> // for auto_ptr
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
 
 #include <pthread.h>
 //
@@ -100,19 +102,6 @@
        ///
        bool start();
 
-       /// Wait for specified frame number (1-based) to be loaded
-       //
-       /// Block caller thread until frame is loaded.
-       ///
-       void wait_for_frame(size_t framenum);
-
-       /// Signal load of given frame number (if anyone waiting for it)
-       void signal_frame_loaded(size_t frameno);
-
-       void lock();
-
-       void unlock();
-
        /// Return true if the MovieLoader thread was started
        bool started() const;
 
@@ -121,10 +110,8 @@
 
 private:
 
-       size_t _waiting_for_frame;
        movie_def_impl& _movie_def;
 
-       pthread_cond_t _frame_reached_condition;
        pthread_mutex_t _mutex;
        pthread_t _thread;
 
@@ -235,7 +222,29 @@
        float   m_frame_rate;
        size_t  m_frame_count;
        int     m_version;
-       size_t  m_loading_frame;
+
+       /// Number of fully loaded frames
+       size_t  _frames_loaded;
+
+       /// A mutex protecting access to _frames_loaded
+       //
+       /// This is needed because the loader thread will
+       /// increment this number, while the virtual machine
+       /// thread will read it.
+       ///
+       mutable boost::mutex _frames_loaded_mutex;
+
+       /// A semaphore to signal load of a specific frame
+       boost::condition _frame_reached_condition;
+
+       /// Set this to trigger signaling of loaded frame
+       //
+       /// Make sure you _frames_loaded_mutex is locked
+       /// when accessing this member !
+       ///
+       size_t _waiting_for_frame;
+
+
        int     m_loading_sound_stream;
        uint32  m_file_length;
 
@@ -255,6 +264,14 @@
        /// asyncronous SWF loader and parser
        MovieLoader _loader;
 
+       /// \brief
+       /// Increment loaded frames count, signaling frame reached condition if
+       /// any thread is waiting for that. See ensure_frame_loaded().
+       ///
+       /// NOTE: this method locks _frames_loaded_mutex
+       ///
+       void incrementLoadedFrames();
+
 public:
 
        movie_def_impl(create_bitmaps_flag cbf, create_font_shapes_flag cfs);
@@ -278,12 +295,23 @@
 
        virtual int     get_version() const { return m_version; }
 
-       virtual size_t  get_loading_frame() const
-       {
-               return m_loading_frame;
-       }
+       /// Get the number of fully loaded frames
+       //
+       /// The number returned is also the index
+       /// of the frame currently being loaded/parsed,
+       /// except when parsing finishes, in which case
+       /// it an index to on-past-last frame.
+       ///
+       /// NOTE: this method locks _frames_loaded_mutex
+       ///
+       virtual size_t  get_loading_frame() const;
 
        /// Get number of bytes loaded from input stream
+       //
+       // FIXME: use a member for bytes loaded, as seek-backs
+       //        are common... also, protect the member with
+       //        a mutex
+       //
        size_t  get_bytes_loaded() const {
                // we assume seek-backs are disabled
                return _str->get_position();
@@ -392,7 +420,7 @@
        void    add_execute_tag(execute_tag* e)
        {
            assert(e);
-           m_playlist[m_loading_frame].push_back(e);
+           m_playlist[_frames_loaded].push_back(e);
        }
 
        /// Need to execute the given tag before entering the
@@ -403,7 +431,7 @@
        void    add_init_action(execute_tag* e)
        {
            assert(e);
-           m_init_action_list[m_loading_frame].push_back(e);
+           m_init_action_list[_frames_loaded].push_back(e);
        }
 
        /// Labels the frame currently being loaded with the
@@ -411,13 +439,13 @@
        /// kept in this object.
        void    add_frame_name(const char* name)
        {
-           assert(m_loading_frame < m_frame_count);
+           assert(_frames_loaded < m_frame_count);
 
            tu_string   n = name;
 
                        if (m_named_frames.get(n, NULL) == false)       // 
frame should not already have a name (?)
                        {
-                   m_named_frames.add(n, m_loading_frame);     // stores 
0-based frame #
+                   m_named_frames.add(n, _frames_loaded);      // stores 
0-based frame #
                        }
        }
 
@@ -441,13 +469,13 @@
 
        virtual const PlayList& get_playlist(size_t frame_number)
        {
-               assert(frame_number <= m_loading_frame);
+               assert(frame_number <= _frames_loaded);
                return m_playlist[frame_number];
        }
 
        virtual const PlayList* get_init_actions(size_t frame_number)
        {
-               assert(frame_number <= m_loading_frame);
+               assert(frame_number <= _frames_loaded);
                //ensure_frame_loaded(frame_number);
                return &m_init_action_list[frame_number];
        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]