Bug 100085 - Centralize sleep function in SAL, with test functions.
Summary: Centralize sleep function in SAL, with test functions.
Status: RESOLVED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: difficultyBeginner, easyHack, skillCpp
Depends on:
Blocks:
 
Reported: 2016-05-27 09:06 UTC by jani
Modified: 2017-02-14 08:58 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jani 2016-05-27 09:06:54 UTC
add a nice example in include/sal if possible - in a verbose comment - that includes the word 'sleep' of how to use the function

cd include/sal
git grep -i sleep

still no hits =)

Change local sleep functions to call central function:
git grep -i sleep


helpcompiler/source/HelpCompiler.cxx-static void impl_sleep( sal_uInt32 nSec )
helpcompiler/source/HelpCompiler.cxx-{
helpcompiler/source/HelpCompiler.cxx-    TimeValue aTime;
helpcompiler/source/HelpCompiler.cxx-    aTime.Seconds = nSec;
helpcompiler/source/HelpCompiler.cxx-    aTime.Nanosec = 0;
helpcompiler/source/HelpCompiler.cxx-
helpcompiler/source/HelpCompiler.cxx:    osl::Thread::wait( aTime );
helpcompiler/source/HelpCompiler.cxx-}

Which is another victim of this API ;-)

cleanup and clarify things like:

sal/qa/osl/thread/test_thread.cxx-        // Give the spawned threads enough time to terminate:
sal/qa/osl/thread/test_thread.cxx-        TimeValue const twentySeconds = { 20, 0 };
sal/qa/osl/thread/test_thread.cxx:        osl::Thread::wait(twentySeconds);

or:

sd/qa/unit/misc-tests.cxx-        TimeValue aSleep(0, 100 * 1000000); // 100 msec
sd/qa/unit/misc-tests.cxx:        osl::Thread::wait(aSleep);

Which could be much clearer with the chrono thing =)


Remark, the wait function in SAL should have a default value of 100 msec, allowing it to be used for context switching.
Comment 1 Stephan Bergmann 2016-05-27 10:13:50 UTC
(In reply to jan iversen from comment #0)
> add a nice example in include/sal if possible - in a verbose comment - that
> includes the word 'sleep' of how to use the function

"the function" presumably referring to osl::Thread::wait (include/osl/thread.hxx)

> cd include/sal
> git grep -i sleep
> 
> still no hits =)
> 
> Change local sleep functions to call central function:
> git grep -i sleep
> 
> 
> helpcompiler/source/HelpCompiler.cxx-static void impl_sleep( sal_uInt32 nSec
> )
> helpcompiler/source/HelpCompiler.cxx-{
> helpcompiler/source/HelpCompiler.cxx-    TimeValue aTime;
> helpcompiler/source/HelpCompiler.cxx-    aTime.Seconds = nSec;
> helpcompiler/source/HelpCompiler.cxx-    aTime.Nanosec = 0;
> helpcompiler/source/HelpCompiler.cxx-
> helpcompiler/source/HelpCompiler.cxx:    osl::Thread::wait( aTime );
> helpcompiler/source/HelpCompiler.cxx-}
> 
> Which is another victim of this API ;-)

(note that the above code in helpcompiler/source/HelpCompiler.cxx no longer exists in that form ever since <https://cgit.freedesktop.org/libreoffice/core/commit/?id=9e7447d39e356857ef5786b513e99cee79385247> "tdf#84323: Make osl::Thread::wait more readable")

> cleanup and clarify things like:
> 
> sal/qa/osl/thread/test_thread.cxx-        // Give the spawned threads enough
> time to terminate:
> sal/qa/osl/thread/test_thread.cxx-        TimeValue const twentySeconds = {
> 20, 0 };
> sal/qa/osl/thread/test_thread.cxx:        osl::Thread::wait(twentySeconds);
> 
> or:
> 
> sd/qa/unit/misc-tests.cxx-        TimeValue aSleep(0, 100 * 1000000); // 100
> msec
> sd/qa/unit/misc-tests.cxx:        osl::Thread::wait(aSleep);
> 
> Which could be much clearer with the chrono thing =)

both (sal/qa/osl/thread/test_thread.cxx, sd/qa/unit/misc-tests.cxx) done with <https://cgit.freedesktop.org/libreoffice/core/commit/?id=9e7447d39e356857ef5786b513e99cee79385247> "tdf#84323: Make osl::Thread::wait more readable" for quite some time now

> Remark, the wait function in SAL should have a default value of 100 msec,
> allowing it to be used for context switching.

???
Comment 2 jani 2016-05-27 10:42:44 UTC
(In reply to Stephan Bergmann from comment #1)

> "the function" presumably referring to osl::Thread::wait
> (include/osl/thread.hxx)

Yes, see original bug also.

> > Remark, the wait function in SAL should have a default value of 100 msec,
> > allowing it to be used for context switching.
> 
> ???

Not all OS are as good as Linux, on e.g. Android and IOS the old function "pthread_yield" is still needed, the implementation is normally a simple wait.

In many program parts, there are no definition of how long to wait, so setting a default value saves us from having a lot of different times (of course with the exception where a specific time is needed).
Comment 3 Stephan Bergmann 2016-05-27 12:21:31 UTC
(In reply to jan iversen from comment #2)
> (In reply to Stephan Bergmann from comment #1)
> > > Remark, the wait function in SAL should have a default value of 100 msec,
> > > allowing it to be used for context switching.
> > 
> > ???
> 
> Not all OS are as good as Linux, on e.g. Android and IOS the old function
> "pthread_yield" is still needed, the implementation is normally a simple
> wait.

If there are scenarios that need to call pthread_yield or sched_yield, I would assume that they do so directly, not trying to mimic that with a call to osl::Thread::wait.  (And I doubt the implementation of those is "normally a simple wait"; what sched_yield is defined to do is to "force the running thread to relinquish the processor until it again becomes the head of its thread list", per SUSv4).

> In many program parts, there are no definition of how long to wait, so
> setting a default value saves us from having a lot of different times (of
> course with the exception where a specific time is needed).

"git grep -w Thread::wait | wc -l" is 17, and of the ones that are calls clearly specifying a fixed time, there's:

  2x std::chrono::milliseconds(100)
  3x std::chrono::milliseconds(500)
  1x std::choron::seconds(1)
  1x std::choron::seconds(12)
  1x std::choron::seconds(20)

so not that "many program parts" would benefit from a (somewhat arbitrary) default there.
Comment 4 jani 2017-02-09 17:43:31 UTC
Seems overtaken by other commits.