[Libreoffice-commits] online.git: net/Socket.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

Michael Meeks michael.meeks at collabora.com
Tue Mar 21 08:52:36 UTC 2017


 net/Socket.cpp         |    2 ++
 wsd/DocumentBroker.cpp |    8 +++++++-
 wsd/DocumentBroker.hpp |    4 ++++
 wsd/LOOLWSD.cpp        |    7 +++----
 4 files changed, 16 insertions(+), 5 deletions(-)

New commits:
commit ce0dffdc12f22fdae9d937cfbcb58df032b126d9
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Mar 20 17:18:41 2017 +0000

    Use callback API to implement alertAllUsers safely and simply.

diff --git a/net/Socket.cpp b/net/Socket.cpp
index 0e5d6eab..008070e3 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -171,6 +171,8 @@ void SocketPoll::dumpState(std::ostream& os)
     // FIXME: NOT thread-safe! _pollSockets is modified from the polling thread!
     os << " Poll [" << _pollSockets.size() << "] - wakeup r: "
        << _wakeup[0] << " w: " << _wakeup[1] << "\n";
+    if (_newCallbacks.size() > 0)
+        os << "\tcallbacks: " << _newCallbacks.size() << "\n";
     os << "\tfd\tevents\trsize\twsize\n";
     for (auto &i : _pollSockets)
         i->dumpState(os);
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index cfdec34a..936fee9a 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -863,6 +863,12 @@ size_t DocumentBroker::removeSessionInternal(const std::string& id)
     return _sessions.size();
 }
 
+
+void DocumentBroker::addCallback(SocketPoll::CallbackFn fn)
+{
+    _poll->addCallback(fn);
+}
+
 void DocumentBroker::addSocketToPoll(const std::shared_ptr<Socket>& socket)
 {
     _poll->insertNewSocket(socket);
@@ -870,7 +876,7 @@ void DocumentBroker::addSocketToPoll(const std::shared_ptr<Socket>& socket)
 
 void DocumentBroker::alertAllUsers(const std::string& msg)
 {
-    Util::assertIsLocked(_mutex);
+    assert(isCorrectThread());
 
     auto payload = std::make_shared<Message>(msg, Message::Dir::Out);
 
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index d3b87b8b..526f873d 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -270,6 +270,10 @@ public:
     /// Removes a session by ID. Returns the new number of sessions.
     size_t removeSession(const std::string& id, bool destroyIfLast = false);
 
+    /// Add a callback to be invoked in our polling thread.
+    void addCallback(SocketPoll::CallbackFn fn);
+
+    /// Transfer this socket into our polling thread / loop.
     void addSocketToPoll(const std::shared_ptr<Socket>& socket);
 
     void alertAllUsers(const std::string& msg);
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index b93098c6..120671e8 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -215,11 +215,10 @@ void alertAllUsersInternal(const std::string& msg)
 
     LOG_INF("Alerting all users: [" << msg << "]");
 
-    //FIXME loolnb: due to thread-affinity of sockets we can't send from here.
-    // for (auto& brokerIt : DocBrokers)
+    for (auto& brokerIt : DocBrokers)
     {
-        // auto lock = brokerIt.second->getLock();
-        // brokerIt.second->alertAllUsers(msg);
+        std::shared_ptr<DocumentBroker> docBroker = brokerIt.second;
+        docBroker->addCallback([msg, docBroker](){ docBroker->alertAllUsers(msg); });
     }
 }
 }


More information about the Libreoffice-commits mailing list