gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_final-


From: Bastiaan Jacques
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_final-2059-g09585f0
Date: Sun, 25 May 2014 18:44:35 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  09585f0bc892b1a5370edc46437583c26948db1e (commit)
       via  54940130147e9471f3a2fdc92fb36eb9a40570da (commit)
       via  8cc4c7fd008c45527c6349e0adb6cefd10f1da85 (commit)
      from  e6a1acfef2ac7e3e39546e3e9b5670e1002c8d35 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=09585f0bc892b1a5370edc46437583c26948db1e


commit 09585f0bc892b1a5370edc46437583c26948db1e
Author: Bastiaan Jacques <address@hidden>
Date:   Sun May 25 20:44:20 2014 +0200

    Add comment about old GCC.

diff --git a/libcore/LoadVariablesThread.cpp b/libcore/LoadVariablesThread.cpp
index b133388..097441a 100644
--- a/libcore/LoadVariablesThread.cpp
+++ b/libcore/LoadVariablesThread.cpp
@@ -150,6 +150,8 @@ LoadVariablesThread::startThread(std::unique_ptr<IOChannel> 
stream)
         throw NetworkException();
     }
 
+    // Passing IOStream* rather than unique_ptr serves to appease GCC 4.6,
+    // which insists the arguments are CopyConstructible rather than Movable.
     _vals = std::async(std::launch::async, completeLoad, stream.release(),
                        std::ref(_canceled));
 }

http://git.savannah.gnu.org/cgit//commit/?id=54940130147e9471f3a2fdc92fb36eb9a40570da


commit 54940130147e9471f3a2fdc92fb36eb9a40570da
Author: Bastiaan Jacques <address@hidden>
Date:   Sun May 25 20:40:50 2014 +0200

    Replace the hodgepodge of formatting with a single style.

diff --git a/libcore/LoadVariablesThread.cpp b/libcore/LoadVariablesThread.cpp
index efc4205..b133388 100644
--- a/libcore/LoadVariablesThread.cpp
+++ b/libcore/LoadVariablesThread.cpp
@@ -1,4 +1,4 @@
-// 
+//
 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
 //   Free Software Foundation, Inc
 //
@@ -33,110 +33,105 @@ namespace gnash {
 // static
 LoadVariablesThread::ValuesMap
 LoadVariablesThread::completeLoad(IOChannel* varstream,
-   std::atomic<bool>& canceled)
+                                  std::atomic<bool>& canceled)
 {
     std::unique_ptr<IOChannel> stream(varstream);
 #ifdef DEBUG_LOAD_VARIABLES
     log_debug("completeLoad called");
 #endif
-        ValuesMap parseResult;
+    ValuesMap parseResult;
 
-       int bytesLoaded = 0;
-       int bytesTotal = stream->size();
+    int bytesLoaded = 0;
+    int bytesTotal = stream->size();
 
-       std::string toparse;
+    std::string toparse;
 
-       const size_t chunkSize = 1024;
-       std::unique_ptr<char[]> buf(new char[chunkSize]);
-       unsigned int parsedLines = 0;
-       // TODO: use read_string ?
-       while ( size_t bytesRead = stream->read(buf.get(), chunkSize) )
-       {
+    const size_t chunkSize = 1024;
+    std::unique_ptr<char[]> buf(new char[chunkSize]);
+    unsigned int parsedLines = 0;
+    // TODO: use read_string ?
+    while ( size_t bytesRead = stream->read(buf.get(), chunkSize) ) {
 #ifdef DEBUG_LOAD_VARIABLES
-            log_debug("Read %u bytes", bytesRead);
+        log_debug("Read %u bytes", bytesRead);
 #endif
 
-               if ( bytesLoaded )
-               {
-                       std::string chunk(buf.get(), bytesRead);
-                       toparse += chunk;
-               }
-               else
-               {
-                       size_t dataSize = bytesRead;
-                       utf8::TextEncoding encoding;
-                       char* ptr = utf8::stripBOM(buf.get(), dataSize,
-                                       encoding);
-                       if ( encoding != utf8::encUTF8 &&
-                            encoding != utf8::encUNSPECIFIED )
-                       {
-                  log_unimpl(_("%s to UTF8 conversion in "
-                                           "MovieClip.loadVariables "
-                                         "input parsing"),
-                                           utf8::textEncodingName(encoding));
-                       }
-                       std::string chunk(ptr, dataSize);
-                       toparse += chunk;
-               }
+        if ( bytesLoaded ) {
+            std::string chunk(buf.get(), bytesRead);
+            toparse += chunk;
+        } else {
+            size_t dataSize = bytesRead;
+            utf8::TextEncoding encoding;
+            char* ptr = utf8::stripBOM(buf.get(), dataSize,
+                                       encoding);
+            if ( encoding != utf8::encUTF8 &&
+                    encoding != utf8::encUNSPECIFIED ) {
+                log_unimpl(_("%s to UTF8 conversion in "
+                             "MovieClip.loadVariables "
+                             "input parsing"),
+                           utf8::textEncodingName(encoding));
+            }
+            std::string chunk(ptr, dataSize);
+            toparse += chunk;
+        }
 
 #ifdef DEBUG_LOAD_VARIABLES
-               log_debug("toparse: %s", toparse);
+        log_debug("toparse: %s", toparse);
 #endif
 
-               // parse remainder
-               size_t lastamp = toparse.rfind('&');
-               if ( lastamp != std::string::npos )
-               {
-                       std::string parseable = toparse.substr(0, lastamp);
+        // parse remainder
+        size_t lastamp = toparse.rfind('&');
+        if ( lastamp != std::string::npos ) {
+            std::string parseable = toparse.substr(0, lastamp);
 #ifdef DEBUG_LOAD_VARIABLES
-                       log_debug("parseable: %s", parseable);
+            log_debug("parseable: %s", parseable);
 #endif
-                        URL::parse_querystring(toparse, parseResult);
-                       toparse = toparse.substr(lastamp+1);
+            URL::parse_querystring(toparse, parseResult);
+            toparse = toparse.substr(lastamp+1);
 #ifdef DEBUG_LOAD_VARIABLES
-                       log_debug("toparse nextline: %s", toparse);
+            log_debug("toparse nextline: %s", toparse);
 #endif
-                       ++parsedLines;
-               }
+            ++parsedLines;
+        }
 
-               bytesLoaded += bytesRead;
+        bytesLoaded += bytesRead;
 
-               // eof, get out !
-               if ( stream->eof() ) break;
+        // eof, get out !
+        if ( stream->eof() ) {
+            break;
+        }
 
-               if ( canceled.load() ) {
-                    log_debug("Cancelling LoadVariables download thread...");
-                       stream.reset();
-                       return parseResult;
-               }
-       }
+        if ( canceled.load() ) {
+            log_debug("Cancelling LoadVariables download thread...");
+            stream.reset();
+            return parseResult;
+        }
+    }
 
-       if ( ! toparse.empty() ) {
-            URL::parse_querystring(toparse, parseResult);
-       }
+    if ( ! toparse.empty() ) {
+        URL::parse_querystring(toparse, parseResult);
+    }
 
-       try {
-               stream->go_to_end();
-       }
-        catch (IOException& ex) {
+    try {
+        stream->go_to_end();
+    } catch (IOException& ex) {
         log_error(_("Stream couldn't seek to end: %s"), ex.what());
-       }
-       
-        bytesLoaded = stream->tell();
-       if ( bytesTotal !=  bytesLoaded ) {
-            log_error(_("Size of 'variables' stream advertised to be %d bytes,"
-                          " but turned out to be %d bytes."),
-                       bytesTotal, bytesLoaded);
-       }
-
-       //dispatchLoadEvent();
-
-        return parseResult;
+    }
+
+    bytesLoaded = stream->tell();
+    if ( bytesTotal !=  bytesLoaded ) {
+        log_error(_("Size of 'variables' stream advertised to be %d bytes,"
+                    " but turned out to be %d bytes."),
+                  bytesTotal, bytesLoaded);
+    }
+
+    //dispatchLoadEvent();
+
+    return parseResult;
 }
 
 LoadVariablesThread::LoadVariablesThread(const StreamProvider& sp,
         const URL& url, const std::string& postdata)
-       : _canceled(false)
+    : _canceled(false)
 {
     startThread(sp.getStream(url, postdata));
 }
@@ -155,18 +150,17 @@ 
LoadVariablesThread::startThread(std::unique_ptr<IOChannel> stream)
         throw NetworkException();
     }
 
-    _vals = std::async(std::launch::async, completeLoad, stream.release(), 
-        std::ref(_canceled));
+    _vals = std::async(std::launch::async, completeLoad, stream.release(),
+                       std::ref(_canceled));
 }
 
 LoadVariablesThread::~LoadVariablesThread()
 {
-       if ( _vals.valid() )
-       {
-               _canceled = true;
-               _vals.wait();
-       }
+    if ( _vals.valid() ) {
+        _canceled = true;
+        _vals.wait();
+    }
 }
 
 
-} // namespace gnash 
+} // namespace gnash

http://git.savannah.gnu.org/cgit//commit/?id=8cc4c7fd008c45527c6349e0adb6cefd10f1da85


commit 8cc4c7fd008c45527c6349e0adb6cefd10f1da85
Author: Bastiaan Jacques <address@hidden>
Date:   Sun May 25 20:16:51 2014 +0200

    Use std::async for launching the thread and marshalling the results
    back to the main thread, avoiding the use of synchronisation primitives.
    
    Also remove some members that are never used.

diff --git a/libcore/LoadVariablesThread.cpp b/libcore/LoadVariablesThread.cpp
index 560244a..efc4205 100644
--- a/libcore/LoadVariablesThread.cpp
+++ b/libcore/LoadVariablesThread.cpp
@@ -30,20 +30,19 @@
 
 namespace gnash {
 
-void
-LoadVariablesThread::completeLoad()
+// static
+LoadVariablesThread::ValuesMap
+LoadVariablesThread::completeLoad(IOChannel* varstream,
+   std::atomic<bool>& canceled)
 {
+    std::unique_ptr<IOChannel> stream(varstream);
 #ifdef DEBUG_LOAD_VARIABLES
     log_debug("completeLoad called");
 #endif
+        ValuesMap parseResult;
 
-
-       // TODO: how to set _bytesTotal ?
-
-       // this is going to override any previous setting,
-       // better do this inside a subclass (in a separate thread)
-       _bytesLoaded = 0;
-       _bytesTotal = _stream->size();
+       int bytesLoaded = 0;
+       int bytesTotal = stream->size();
 
        std::string toparse;
 
@@ -51,13 +50,13 @@ LoadVariablesThread::completeLoad()
        std::unique_ptr<char[]> buf(new char[chunkSize]);
        unsigned int parsedLines = 0;
        // TODO: use read_string ?
-       while ( size_t bytesRead = _stream->read(buf.get(), chunkSize) )
+       while ( size_t bytesRead = stream->read(buf.get(), chunkSize) )
        {
 #ifdef DEBUG_LOAD_VARIABLES
             log_debug("Read %u bytes", bytesRead);
 #endif
 
-               if ( _bytesLoaded )
+               if ( bytesLoaded )
                {
                        std::string chunk(buf.get(), bytesRead);
                        toparse += chunk;
@@ -92,7 +91,7 @@ LoadVariablesThread::completeLoad()
 #ifdef DEBUG_LOAD_VARIABLES
                        log_debug("parseable: %s", parseable);
 #endif
-                       parse(parseable);
+                        URL::parse_querystring(toparse, parseResult);
                        toparse = toparse.substr(lastamp+1);
 #ifdef DEBUG_LOAD_VARIABLES
                        log_debug("toparse nextline: %s", toparse);
@@ -100,93 +99,72 @@ LoadVariablesThread::completeLoad()
                        ++parsedLines;
                }
 
-               _bytesLoaded += bytesRead;
+               bytesLoaded += bytesRead;
 
                // eof, get out !
-               if ( _stream->eof() ) break;
+               if ( stream->eof() ) break;
 
-               if ( cancelRequested() ) {
+               if ( canceled.load() ) {
                     log_debug("Cancelling LoadVariables download thread...");
-                       _stream.reset();
-                       return;
+                       stream.reset();
+                       return parseResult;
                }
        }
 
        if ( ! toparse.empty() ) {
-               parse(toparse);
+            URL::parse_querystring(toparse, parseResult);
        }
 
        try {
-               _stream->go_to_end();
+               stream->go_to_end();
        }
         catch (IOException& ex) {
         log_error(_("Stream couldn't seek to end: %s"), ex.what());
        }
        
-    _bytesLoaded = _stream->tell();
-       if ( _bytesTotal !=  _bytesLoaded ) {
+        bytesLoaded = stream->tell();
+       if ( bytesTotal !=  bytesLoaded ) {
             log_error(_("Size of 'variables' stream advertised to be %d bytes,"
                           " but turned out to be %d bytes."),
-                       _bytesTotal, _bytesLoaded);
-               _bytesTotal = _bytesLoaded;
+                       bytesTotal, bytesLoaded);
        }
 
-       _stream.reset(); // we don't need the IOChannel anymore
-
        //dispatchLoadEvent();
-       setCompleted();
+
+        return parseResult;
 }
 
 LoadVariablesThread::LoadVariablesThread(const StreamProvider& sp,
         const URL& url, const std::string& postdata)
-       :
-       _bytesLoaded(0),
-       _bytesTotal(0),
-       _stream(sp.getStream(url, postdata)),
-       _completed(false),
-       _canceled(false)
+       : _canceled(false)
 {
-       if ( ! _stream.get() )
-       {
-               throw NetworkException();
-       }
+    startThread(sp.getStream(url, postdata));
 }
 
 LoadVariablesThread::LoadVariablesThread(const StreamProvider& sp,
         const URL& url)
-       :
-       _bytesLoaded(0),
-       _bytesTotal(0),
-       _stream(sp.getStream(url)),
-       _completed(false),
-       _canceled(false)
+    : _canceled(false)
 {
-       if ( ! _stream.get() )
-       {
-               throw NetworkException();
-       }
+    startThread(sp.getStream(url));
 }
 
 void
-LoadVariablesThread::cancel()
+LoadVariablesThread::startThread(std::unique_ptr<IOChannel> stream)
 {
-       std::lock_guard<std::mutex> lock(_mutex);
-       _canceled = true;
-}
+    if (!stream) {
+        throw NetworkException();
+    }
 
-bool
-LoadVariablesThread::cancelRequested()
-{
-       std::lock_guard<std::mutex> lock(_mutex);
-       return _canceled;
+    _vals = std::async(std::launch::async, completeLoad, stream.release(), 
+        std::ref(_canceled));
 }
 
 LoadVariablesThread::~LoadVariablesThread()
 {
-       if ( _thread.joinable() )
+       if ( _vals.valid() )
        {
-               cancel();
-               _thread.join();
+               _canceled = true;
+               _vals.wait();
        }
 }
 
diff --git a/libcore/LoadVariablesThread.h b/libcore/LoadVariablesThread.h
index 0a6cbd0..eead251 100644
--- a/libcore/LoadVariablesThread.h
+++ b/libcore/LoadVariablesThread.h
@@ -23,9 +23,8 @@
 
 #include <string>
 #include <map>
-#include <thread>
-#include <mutex>
-#include <functional> 
+#include <functional>
+#include <future>
 #include <cassert>
 
 #include "URL.h" // for inlines
@@ -79,133 +78,39 @@ public:
        ~LoadVariablesThread();
 
        /// Return the name,value map parsed out of the loaded stream
-       ValuesMap& getValues()
+       ValuesMap getValues()
        {
-               return _vals;
+               return _vals.get();
        }
 
-       /// Start the load and parse thread
-       void process()
-       {
-               assert(!_thread.joinable());
-               assert(_stream.get());
-               _thread = std::thread(
-                    std::bind(LoadVariablesThread::execLoadingThread, this));
-       }
-
-       /// Cancel a download in progress
-       //
-       /// Locks _mutex
-       ///
-       void cancel();
-
-       /// Return true if loading/parsing is in progress
-       bool inProgress()
-       {
-               // TODO: should we mutex-protect this ?
-               return _thread.joinable();
-       }
-
-       /// Mutex-protected inspector for thread completion
-       //
-       /// Only call this method from the same thread that
-       /// also called process(), as the thread will be joined
-       /// if it completed.
-       ///
        bool completed()
        {
-               std::lock_guard<std::mutex> lock(_mutex);
-               if (  _completed && _thread.joinable() )
-               {
-                       _thread.join();
-               }
-               return _completed;
+#if (__GNUC__ == 4 && __GNUC_MINOR__ <= 6)
+                return _vals.wait_for(std::chrono::seconds(0));
+#else
+                std::future_status status = 
_vals.wait_for(std::chrono::seconds(0));
+                return status == std::future_status::ready;
+#endif
        }
 
-       size_t getBytesLoaded() const
-       {
-               // TODO: should we mutex-protect this ?
-               return _bytesLoaded;
-       }
-
-       size_t getBytesTotal() const
-       {
-               // TODO: should we mutex-protect this ?
-               return _bytesTotal;
-       }
-
-
 private:
 
        /// Prevent copy
        LoadVariablesThread& operator==(const LoadVariablesThread&); 
        LoadVariablesThread(const LoadVariablesThread&); 
 
-       /// Since I haven't found a way to pass boost::thread 
-       /// constructor a non-static function, this is here to
-       /// workaround that limitation (in either boost or more
-       /// likely my own knowledge of it)
-       static void execLoadingThread(LoadVariablesThread* ptr)
-       {
-               //log_debug("LoadVars loading thread started");
-               ptr->completeLoad();
-               //log_debug("LoadVars loading thread completed");
-       }
-
-
-       /// Mutex-protected mutator for thread completion
-       void setCompleted()
-       {
-               std::lock_guard<std::mutex> lock(_mutex);
-               _completed = true;
-               //log_debug("Completed");
-       }
-
+        void startThread(std::unique_ptr<IOChannel> stream);
 
        /// Load all data from the _stream input.
        //
        /// This function should be run by a separate thread.
        ///
-       void completeLoad();
-
-       /// Parse an url-encoded query string
-       //
-       /// Variables in the string will be added as properties
-       /// of this object.
-       ///
-       /// @param querystring
-       ///     An url-encoded query string.
-       ///     The string will be parsed using URL::parse_querystring
-       ///
-       /// @return the number of variables found in the string
-       ///
-       size_t parse(const std::string& str)
-       {
-               URL::parse_querystring(str, _vals);
-               return _vals.size();
-       }
-
-       /// Check if download cancel was requested
-       //
-       /// Locks _mutex
-       ///
-       bool cancelRequested();
-
-       size_t _bytesLoaded;
-
-       size_t _bytesTotal;
-
-        std::unique_ptr<IOChannel> _stream;
-
-        std::thread _thread;
-
-       ValuesMap _vals;
-
-       bool _completed;
+       static ValuesMap completeLoad(IOChannel* stream,
+                                      std::atomic<bool>& canceled);
 
-       bool _canceled;
+        std::future<ValuesMap> _vals;
 
-       std::mutex _mutex;
+       std::atomic<bool> _canceled;
 };
 
 } // namespace gnash
diff --git a/libcore/MovieClip.cpp b/libcore/MovieClip.cpp
index a1fbfa5..67fdf64 100644
--- a/libcore/MovieClip.cpp
+++ b/libcore/MovieClip.cpp
@@ -1899,7 +1899,6 @@ MovieClip::loadVariables(const std::string& urlstr,
             }
             _loadVariableRequests.push_back(new LoadVariablesThread(sp, url));
         }
-        _loadVariableRequests.back().process();
     }
     catch (const NetworkException& ex) {
         log_error(_("Could not load variables from %s"), url.str());
@@ -1909,9 +1908,7 @@ MovieClip::loadVariables(const std::string& urlstr,
 void
 MovieClip::processCompletedLoadVariableRequest(LoadVariablesThread& request)
 {
-    assert(request.completed());
-
-    MovieVariables& vals = request.getValues();
+    MovieVariables vals = request.getValues();
     setVariables(vals);
 
     // We want to call a clip-event too if available, see bug #22116

-----------------------------------------------------------------------

Summary of changes:
 libcore/LoadVariablesThread.cpp |  216 +++++++++++++++++----------------------
 libcore/LoadVariablesThread.h   |  125 +++--------------------
 libcore/MovieClip.cpp           |    5 +-
 3 files changed, 111 insertions(+), 235 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

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