Timer - shutdown and re-start salhelper::Timer thread.

Necessary for lok background save.

Change-Id: Ib78f67f124dcd5b2a8b50c65ea58a9e1eb894ade
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182931
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
(cherry picked from commit 79197949d757c40f750406f59e85d6efe02bf584)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185641
This commit is contained in:
Michael Meeks
2025-05-22 11:57:11 +02:00
committed by Caolán McNamara
parent 29edbf28fc
commit 0117608965
4 changed files with 80 additions and 13 deletions
+5
View File
@@ -77,6 +77,7 @@
#include <rtl/uri.hxx>
#include <svl/cryptosign.hxx>
#include <linguistic/misc.hxx>
#include <salhelper/timer.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <comphelper/random.hxx>
#include <comphelper/base64.hxx>
@@ -3577,11 +3578,15 @@ static int lo_joinThreads(LibreOfficeKit* /* pThis */)
comphelper::getProcessComponentContext()),
css::uno::UNO_QUERY_THROW)->flush();
salhelper::Timer::joinThread();
return 1;
}
static void lo_startThreads(LibreOfficeKit* /* pThis */)
{
salhelper::Timer::startThread();
auto ucpWebdav = xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.ucb.WebDAVManager", xContext);
auto joinable = dynamic_cast<comphelper::LibreOfficeKit::ThreadJoinable *>(ucpWebdav.get());
+8
View File
@@ -177,6 +177,14 @@ public:
*/
TTimeValue SAL_CALL getRemainingTime() const;
/** Internal method to shutdown the timer thread
*/
static void SAL_CALL joinThread();
/** Internal method to re-start the timer thread if necessary
*/
static void SAL_CALL startThread();
protected:
/** Destructor.
+5
View File
@@ -131,6 +131,11 @@ LIBO_UDK_3.6 { # symbols available in >= LibO 3.6
# non-virtual thunk to salhelper::Thread::run()
} UDK_3.1;
PRIVATE_1.0 {
_ZN9salhelper5Timer10joinThreadEv;
_ZN9salhelper5Timer11startThreadEv;
};
# Unique libstdc++ symbols:
GLIBCXX_3.4 {
global:
+62 -13
View File
@@ -20,16 +20,15 @@
#include <osl/thread.hxx>
#include <condition_variable>
#include <mutex>
#include <condition_variable>
using namespace salhelper;
class salhelper::TimerManager final : public osl::Thread
{
public:
TimerManager();
TimerManager(salhelper::Timer* &pHead, std::mutex &Lock);
~TimerManager();
/// register timer
@@ -48,24 +47,65 @@ protected:
/// Checking and triggering of a timer event
void checkForTimeout();
/// sorted-queue data
salhelper::Timer* m_pHead;
salhelper::Timer* &m_pHead;
bool m_terminate;
/// List Protection
std::mutex m_Lock;
std::mutex &m_Lock;
/// Signal the insertion of a timer
std::condition_variable m_notEmpty;
/// "Singleton Pattern"
//static salhelper::TimerManager* m_pManager;
};
namespace
namespace {
class TimerManagerImpl final
{
salhelper::TimerManager& getTimerManager()
std::mutex m_Lock; // shared lock with each impl. thread
salhelper::Timer* m_pHead; // the underlying shared queue
std::shared_ptr<TimerManager> m_pImpl;
public:
TimerManagerImpl() : m_pHead(nullptr) { }
void joinThread()
{
static salhelper::TimerManager aManager;
m_pImpl.reset();
}
void startThread()
{
std::lock_guard Guard(m_Lock);
if (m_pHead)
ensureThread();
}
std::shared_ptr<TimerManager> ensureThread()
{
if (!m_pImpl)
m_pImpl.reset(new TimerManager(m_pHead, m_Lock));
return m_pImpl;
}
void registerTimer(salhelper::Timer* pTimer)
{
ensureThread()->registerTimer(pTimer);
}
void unregisterTimer(salhelper::Timer * pTimer)
{
ensureThread()->unregisterTimer(pTimer);
}
bool lookupTimer(const salhelper::Timer* pTimer)
{
return ensureThread()->lookupTimer(pTimer);
}
};
TimerManagerImpl& getTimerManager()
{
static TimerManagerImpl aManager;
return aManager;
}
}
@@ -195,6 +235,16 @@ TTimeValue Timer::getRemainingTime() const
return TTimeValue(secs, nsecs);
}
void Timer::joinThread()
{
getTimerManager().joinThread();
}
void Timer::startThread()
{
getTimerManager().startThread();
}
/** The timer manager cleanup has been removed (no thread is killed anymore),
so the thread leaks.
@@ -205,8 +255,8 @@ TTimeValue Timer::getRemainingTime() const
when there are no timers anymore !
**/
TimerManager::TimerManager() :
m_pHead(nullptr), m_terminate(false)
TimerManager::TimerManager(salhelper::Timer* &pHead, std::mutex &Lock) :
m_pHead(pHead), m_terminate(false), m_Lock(Lock)
{
// start thread
create();
@@ -387,7 +437,6 @@ void TimerManager::run()
checkForTimeout();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */