Skip to content

Commit f129913

Browse files
committed
cool#11064 vcl lok: fold the scheduler info into the anyinput callback
This changes the LOK API added in commit e9e39e4 (cool#11064 vcl lok: expose info about the scheduler, 2025-02-14) so that a LOK client doesn't have to query the priority of the most urgent task: instead the anyInput callback gets it as a parameter. The scheduler is a hot path and it's not expected this priority information would be needed in other places, so folding the new LOK API into the anyInput callback simplifies things. Change-Id: I1385055bfa27f47a243d40683b54cb2ddc9d33bd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181878 Tested-by: Jenkins Reviewed-by: Miklos Vajna <[email protected]>
1 parent ccefc5e commit f129913

File tree

9 files changed

+45
-69
lines changed

9 files changed

+45
-69
lines changed

comphelper/source/misc/lok.cxx

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ static bool g_bLocalRendering(false);
4242

4343
static Compat g_eCompatFlags(Compat::none);
4444

45-
static std::function<bool(void*)> g_pAnyInputCallback;
45+
static std::function<bool(void*, int)> g_pAnyInputCallback;
4646
static void* g_pAnyInputCallbackData;
47+
static std::function<int()> g_pMostUrgentPriorityGetter;
4748

4849
static std::function<void(int)> g_pViewSetter;
4950
static std::function<int()> g_pViewGetter;
@@ -329,10 +330,11 @@ void statusIndicatorFinish()
329330
pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Finish, 0, nullptr);
330331
}
331332

332-
void setAnyInputCallback(const std::function<bool(void*)>& pAnyInputCallback, void* pData)
333+
void setAnyInputCallback(const std::function<bool(void*, int)>& pAnyInputCallback, void* pData, std::function<int()> pMostUrgentPriorityGetter)
333334
{
334335
g_pAnyInputCallback = pAnyInputCallback;
335336
g_pAnyInputCallbackData = pData;
337+
g_pMostUrgentPriorityGetter = pMostUrgentPriorityGetter;
336338
}
337339

338340
bool anyInput()
@@ -342,7 +344,8 @@ bool anyInput()
342344
// Ignore input events during background save.
343345
if (!g_bForkedChild && g_pAnyInputCallback && g_pAnyInputCallbackData)
344346
{
345-
bRet = g_pAnyInputCallback(g_pAnyInputCallbackData);
347+
int nMostUrgentPriority = g_pMostUrgentPriorityGetter();
348+
bRet = g_pAnyInputCallback(g_pAnyInputCallbackData, nMostUrgentPriority);
346349
}
347350

348351
return bRet;

desktop/source/lib/init.cxx

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
#include <comphelper/diagnose_ex.hxx>
199199
#include <vcl/uitest/uiobject.hxx>
200200
#include <vcl/jsdialog/executor.hxx>
201+
#include <vcl/scheduler.hxx>
201202

202203
// Needed for getUndoManager()
203204
#include <com/sun/star/document/XUndoManager.hpp>
@@ -7665,7 +7666,9 @@ static void lo_registerAnyInputCallback(LibreOfficeKit* /*pThis*/,
76657666
void* pData)
76667667
{
76677668
SolarMutexGuard aGuard;
7668-
comphelper::LibreOfficeKit::setAnyInputCallback(pAnyInputCallback, pData);
7669+
comphelper::LibreOfficeKit::setAnyInputCallback(pAnyInputCallback, pData, []() -> int {
7670+
return Scheduler::GetMostUrgentTaskPriority();
7671+
});
76697672
}
76707673

76717674
static bool bInitialized = false;

include/LibreOfficeKit/LibreOfficeKitTypes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef int (*LibreOfficeKitPollCallback)(void* pData, int timeoutUs);
2626
typedef void (*LibreOfficeKitWakeCallback)(void* pData);
2727

2828
/// @see lok::Office::registerAnyInputCallback()
29-
typedef bool (*LibreOfficeKitAnyInputCallback)(void* pData);
29+
typedef bool (*LibreOfficeKitAnyInputCallback)(void* pData, int nMostUrgentPriority);
3030

3131
#ifdef __cplusplus
3232
}

include/comphelper/lok.hxx

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ COMPHELPER_DLLPUBLIC void statusIndicatorFinish();
138138

139139
COMPHELPER_DLLPUBLIC void setBlockedCommandList(const char* blockedCommandList);
140140

141-
COMPHELPER_DLLPUBLIC void setAnyInputCallback(const std::function<bool(void*)>& pAnyInputCallback,
142-
void* pData);
141+
COMPHELPER_DLLPUBLIC void
142+
setAnyInputCallback(const std::function<bool(void*, int)>& pAnyInputCallback, void* pData,
143+
std::function<int()> pMostUrgentPriorityGetter);
143144
COMPHELPER_DLLPUBLIC bool anyInput();
144145

145146
// These allow setting callbacks, so that set/get of a LOK view is possible even in code that is

include/vcl/scheduler.hxx

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
#include <vcl/dllapi.h>
2424

2525
struct ImplSchedulerContext;
26-
namespace tools
27-
{
28-
class JsonWriter;
29-
}
3026

3127
class VCL_DLLPUBLIC Scheduler final
3228
{
@@ -86,7 +82,7 @@ public:
8682
/// Return the current state of deterministic mode.
8783
static bool GetDeterministicMode();
8884

89-
static void dumpAsJSON(tools::JsonWriter& rJsonWriter);
85+
static int GetMostUrgentTaskPriority();
9086

9187
// Makes sure that idles are not processed, until the guard is destroyed
9288
struct VCL_DLLPUBLIC IdlesLockGuard final

sfx2/qa/cppunit/view.cxx

+5-14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <rtl/ustrbuf.hxx>
2828
#include <comphelper/base64.hxx>
2929
#include <comphelper/propertyvalue.hxx>
30+
#include <vcl/scheduler.hxx>
3031

3132
using namespace com::sun::star;
3233

@@ -228,21 +229,11 @@ CPPUNIT_TEST_FIXTURE(Sfx2ViewTest, testScheduler)
228229
mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
229230

230231
// When asking for the state of the scheduler:
231-
tools::JsonWriter aWriter;
232-
SfxLokHelper::getCommandValues(aWriter, ".uno:Scheduler");
233-
OString aJson = aWriter.finishAndGetAsOString();
232+
int nRet = Scheduler::GetMostUrgentTaskPriority();
234233

235-
// Then make sure we get an int priority:
236-
CPPUNIT_ASSERT(SfxLokHelper::supportsCommand(u"Scheduler"));
237-
std::stringstream aStream{ std::string(aJson) };
238-
boost::property_tree::ptree aTree;
239-
boost::property_tree::read_json(aStream, aTree);
240-
auto it = aTree.find("mostUrgentPriority");
241-
// Without the accompanying fix in place, this test would have failed, this JSON key was
242-
// missing.
243-
CPPUNIT_ASSERT(it != aTree.not_found());
244-
// This returns TaskPriority::HIGH_IDLE, but just make sure we get an int.
245-
it->second.get_value<int>();
234+
// Then make sure we get a priority:
235+
// This returns TaskPriority::HIGH_IDLE, but just make sure we get a positive priority.
236+
CPPUNIT_ASSERT(nRet != -1);
246237
}
247238
#endif
248239

sfx2/source/view/lokhelper.cxx

+9-32
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include <tools/json_writer.hxx>
4545
#include <svl/cryptosign.hxx>
4646
#include <tools/urlobj.hxx>
47-
#include <vcl/scheduler.hxx>
4847

4948
#include <boost/property_tree/json_parser.hpp>
5049

@@ -997,8 +996,7 @@ void SfxLokHelper::addCertificates(const std::vector<std::string>& rCerts)
997996

998997
bool SfxLokHelper::supportsCommand(std::u16string_view rCommand)
999998
{
1000-
static const std::initializer_list<std::u16string_view> vSupport
1001-
= { u"Signature", u"Scheduler" };
999+
static const std::initializer_list<std::u16string_view> vSupport = { u"Signature" };
10021000

10031001
return std::find(vSupport.begin(), vSupport.end(), rCommand) != vSupport.end();
10041002
}
@@ -1030,11 +1028,14 @@ std::map<OUString, OUString> SfxLokHelper::parseCommandParameters(std::u16string
10301028
return aMap;
10311029
}
10321030

1033-
namespace
1034-
{
1035-
/// Implements getCommandValues(".uno:Signature").
1036-
void GetSignature(tools::JsonWriter& rJsonWriter, std::string_view rCommand)
1031+
void SfxLokHelper::getCommandValues(tools::JsonWriter& rJsonWriter, std::string_view rCommand)
10371032
{
1033+
static constexpr OString aSignature(".uno:Signature"_ostr);
1034+
if (!o3tl::starts_with(rCommand, aSignature))
1035+
{
1036+
return;
1037+
}
1038+
10381039
SfxObjectShell* pObjectShell = SfxObjectShell::Current();
10391040
if (!pObjectShell)
10401041
{
@@ -1052,7 +1053,7 @@ void GetSignature(tools::JsonWriter& rJsonWriter, std::string_view rCommand)
10521053
}
10531054
pObjectShell->SignDocumentContentUsingCertificate(aSigningContext);
10541055
// Set commandName, this is a reply to a request.
1055-
rJsonWriter.put("commandName", ".uno:Signature");
1056+
rJsonWriter.put("commandName", aSignature);
10561057
auto aCommandValues = rJsonWriter.startNode("commandValues");
10571058
rJsonWriter.put("signatureTime", aSigningContext.m_nSignatureTime);
10581059

@@ -1063,30 +1064,6 @@ void GetSignature(tools::JsonWriter& rJsonWriter, std::string_view rCommand)
10631064
rJsonWriter.put("digest", aBuffer.makeStringAndClear());
10641065
}
10651066

1066-
/// Implements getCommandValues(".uno:Scheduler").
1067-
void GetScheduler(tools::JsonWriter& rJsonWriter)
1068-
{
1069-
Scheduler::dumpAsJSON(rJsonWriter);
1070-
}
1071-
}
1072-
1073-
void SfxLokHelper::getCommandValues(tools::JsonWriter& rJsonWriter, std::string_view rCommand)
1074-
{
1075-
static constexpr OString aSignature(".uno:Signature"_ostr);
1076-
static constexpr OString aScheduler(".uno:Scheduler"_ostr);
1077-
if (o3tl::starts_with(rCommand, aSignature))
1078-
{
1079-
GetSignature(rJsonWriter, rCommand);
1080-
return;
1081-
}
1082-
1083-
if (o3tl::starts_with(rCommand, aScheduler))
1084-
{
1085-
GetScheduler(rJsonWriter);
1086-
return;
1087-
}
1088-
}
1089-
10901067
void SfxLokHelper::notifyUpdate(SfxViewShell const* pThisView, int nType)
10911068
{
10921069
if (DisableCallbacks::disabled() || !pThisView)

sw/qa/extras/tiledrendering/tiledrendering2.cxx

+11-3
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,19 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testAsyncLayout)
199199
class AnyInputCallback final
200200
{
201201
public:
202-
static bool callback(void* /*pData*/) { return true; }
202+
static bool callback(void* /*pData*/, int /*nPriority*/) { return true; }
203203

204-
AnyInputCallback() { comphelper::LibreOfficeKit::setAnyInputCallback(&callback, this); }
204+
AnyInputCallback()
205+
{
206+
comphelper::LibreOfficeKit::setAnyInputCallback(&callback, this,
207+
[]() -> int { return -1; });
208+
}
205209

206-
~AnyInputCallback() { comphelper::LibreOfficeKit::setAnyInputCallback(nullptr, nullptr); }
210+
~AnyInputCallback()
211+
{
212+
comphelper::LibreOfficeKit::setAnyInputCallback(nullptr, nullptr,
213+
[]() -> int { return -1; });
214+
}
207215
};
208216

209217
CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testAnyInput)

vcl/source/app/scheduler.cxx

+5-8
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ Scheduler::IdlesLockGuard::~IdlesLockGuard()
302302
osl_atomic_decrement(&rSchedCtx.mnIdlesLockCount);
303303
}
304304

305-
void Scheduler::dumpAsJSON(tools::JsonWriter& rJsonWriter)
305+
int Scheduler::GetMostUrgentTaskPriority()
306306
{
307307
// Similar to Scheduler::CallbackTaskScheduling(), figure out the most urgent priority, but
308308
// don't actually invoke any task.
@@ -311,15 +311,13 @@ void Scheduler::dumpAsJSON(tools::JsonWriter& rJsonWriter)
311311
ImplSchedulerContext& rSchedCtx = pSVData->maSchedCtx;
312312
if (!rSchedCtx.mbActive || rSchedCtx.mnTimerPeriod == InfiniteTimeoutMs)
313313
{
314-
rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority);
315-
return;
314+
return nMostUrgentPriority;
316315
}
317316

318317
sal_uInt64 nTime = tools::Time::GetSystemTicks();
319318
if (nTime < rSchedCtx.mnTimerStart + rSchedCtx.mnTimerPeriod - 1)
320319
{
321-
rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority);
322-
return;
320+
return nMostUrgentPriority;
323321
}
324322

325323
for (int nTaskPriority = 0; nTaskPriority < PRIO_COUNT; ++nTaskPriority)
@@ -335,14 +333,13 @@ void Scheduler::dumpAsJSON(tools::JsonWriter& rJsonWriter)
335333
if (nReadyPeriod == ImmediateTimeoutMs)
336334
{
337335
nMostUrgentPriority = nTaskPriority;
338-
rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority);
339-
return;
336+
return nMostUrgentPriority;
340337
}
341338
}
342339
pSchedulerData = pSchedulerData->mpNext;
343340
}
344341
}
345-
rJsonWriter.put("mostUrgentPriority", nMostUrgentPriority);
342+
return nMostUrgentPriority;
346343
}
347344

348345
inline void Scheduler::UpdateSystemTimer( ImplSchedulerContext &rSchedCtx,

0 commit comments

Comments
 (0)