Library: verify thread self-recognition
...this function was also ported to the new wrapper, and can be verified now in a much more succinct way. ''This completes porting of the thread-wrapper''
This commit is contained in:
parent
1d625a01e0
commit
d79e33f797
4 changed files with 46 additions and 39 deletions
|
|
@ -196,7 +196,7 @@ namespace lib {
|
|||
return *value_;
|
||||
}
|
||||
|
||||
template<typename TY>
|
||||
template<typename TY =RES>
|
||||
TY
|
||||
get() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ namespace lib {
|
|||
, threadImpl_{forward<ARGS> (args)... }
|
||||
{ }
|
||||
|
||||
/** determine if the currently executing code runs within this thread */
|
||||
/** detect if the currently executing code runs within this thread */
|
||||
bool invokedWithinThread() const;
|
||||
|
||||
void markThreadStart();
|
||||
|
|
@ -294,6 +294,9 @@ namespace lib {
|
|||
return Policy::isLive();
|
||||
}
|
||||
|
||||
/** @return does this call happen from within this thread? */
|
||||
using Policy::invokedWithinThread;
|
||||
|
||||
|
||||
/** Create a new thread to execute the given operation.
|
||||
* The new thread starts up synchronously, can't be cancelled and it can't be joined.
|
||||
|
|
|
|||
|
|
@ -26,10 +26,7 @@
|
|||
|
||||
|
||||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
|
||||
#include "lib/thread.hpp"
|
||||
#include "lib/error.hpp"
|
||||
|
||||
using test::Test;
|
||||
|
||||
|
|
@ -38,35 +35,12 @@ using test::Test;
|
|||
namespace lib {
|
||||
namespace test {
|
||||
|
||||
namespace {
|
||||
|
||||
class TestThread
|
||||
: Thread
|
||||
{
|
||||
public:
|
||||
TestThread()
|
||||
: Thread{"test Thread self recognition"
|
||||
,[&]()
|
||||
{
|
||||
CHECK (invocation_happens_within_this_thread());
|
||||
}}
|
||||
{ }
|
||||
|
||||
bool
|
||||
invocation_happens_within_this_thread()
|
||||
{
|
||||
return invokedWithinThread();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
/******************************************************//**
|
||||
* @test verify the ability of a thread to detect code
|
||||
* executing within the thread itself.
|
||||
*
|
||||
* @see Thread::invokedWithinThread()
|
||||
* @see thread::ThreadWrapper::invokedWithinThread()
|
||||
* @see steam::control::DispatcherLoop::stateIsSynched()
|
||||
*/
|
||||
class ThreadWrapperSelfRecognitionTest_test : public Test
|
||||
|
|
@ -75,11 +49,13 @@ namespace test {
|
|||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
TestThread testThread;
|
||||
ThreadJoinable<bool> testThread{"Thread self detection"
|
||||
,[&]{
|
||||
return testThread.invokedWithinThread();
|
||||
}};
|
||||
|
||||
CHECK (not testThread.invocation_happens_within_this_thread());
|
||||
|
||||
usleep(10); // give the thread a chance to run before shutdown
|
||||
CHECK (not testThread.invokedWithinThread());
|
||||
CHECK (testThread.join().get<bool>());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -79016,7 +79016,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695313755664" HGAP="-12" ID="ID_1075854169" MODIFIED="1695313767920" TEXT="Umstellung der Codebasis" VSHIFT="21">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1695313774171" ID="ID_1529952681" MODIFIED="1695340435812" TEXT="spezielle Abhängigkeiten">
|
||||
<node COLOR="#338800" CREATED="1695313774171" FOLDED="true" ID="ID_1529952681" MODIFIED="1696025089421" TEXT="spezielle Abhängigkeiten">
|
||||
<icon BUILTIN="help"/>
|
||||
<node CREATED="1695313807671" ID="ID_1031643072" MODIFIED="1695313818061" TEXT="vault::Thread vs vault::ThreadJoinable">
|
||||
<node CREATED="1695335467170" ID="ID_920953501" MODIFIED="1695335514560" TEXT="das erweist sich als praktische Abkürzung"/>
|
||||
|
|
@ -79268,7 +79268,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1695394188133" ID="ID_1229328590" MODIFIED="1696015383325" TEXT="Umbau">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1695597011139" ID="ID_125138411" MODIFIED="1695859127749" TEXT="Kopie des bestehenden Thread-Wrappers umschreiben">
|
||||
<node COLOR="#338800" CREATED="1695597011139" FOLDED="true" ID="ID_125138411" MODIFIED="1695859127749" TEXT="Kopie des bestehenden Thread-Wrappers umschreiben">
|
||||
<linktarget COLOR="#6ebe5a" DESTINATION="ID_125138411" ENDARROW="Default" ENDINCLINATION="43;-18;" ID="Arrow_ID_195305087" SOURCE="ID_215388471" STARTARROW="None" STARTINCLINATION="-113;6;"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#435e98" CREATED="1695597146529" ID="ID_938038908" MODIFIED="1695948178166" TEXT="std::thread liefert fast alle Funktionalität">
|
||||
|
|
@ -79954,7 +79954,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1695394205547" ID="ID_1719816317" MODIFIED="1696015377362" TEXT="Tests umstellen und modernisieren">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1695394270093" ID="ID_585437655" MODIFIED="1696007768225" TEXT="ThreadWrapper_test">
|
||||
<node COLOR="#338800" CREATED="1695394270093" FOLDED="true" ID="ID_585437655" MODIFIED="1696007768225" TEXT="ThreadWrapper_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1695911786871" ID="ID_1371513124" MODIFIED="1695911794232" TEXT="läuft nach Umstellung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
|
|
@ -80020,7 +80020,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1695394665822" ID="ID_881973960" MODIFIED="1696015353416" TEXT="ThreadWrapperJoin_test">
|
||||
<node COLOR="#338800" CREATED="1695394665822" FOLDED="true" ID="ID_881973960" MODIFIED="1696015353416" TEXT="ThreadWrapperJoin_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1695911786871" ID="ID_1004221223" MODIFIED="1695911801372" TEXT="läuft nach Umstellung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
|
|
@ -80040,8 +80040,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node COLOR="#435e98" CREATED="1696010036948" ID="ID_440877573" MODIFIED="1696015360375" TEXT="Fehlerbehandlung"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695394744028" ID="ID_1755648327" MODIFIED="1695394746744" TEXT="ThreadWrapperSelfRecognitionTest_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1695394744028" FOLDED="true" ID="ID_1755648327" MODIFIED="1696025182064" TEXT="ThreadWrapperSelfRecognition_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1695911804614" ID="ID_174546781" MODIFIED="1695911929623" TEXT="Scheitert mit Fehler">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
|
@ -80060,6 +80060,34 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="broken-line"/>
|
||||
<icon BUILTIN="button_cancel"/>
|
||||
<node CREATED="1696023930450" ID="ID_1910034301" MODIFIED="1696023935701" TEXT="nicht mehr reproduzierbar"/>
|
||||
<node CREATED="1696023936220" ID="ID_1057418547" MODIFIED="1696023963855" TEXT="(inzwischen diverse Fixes zum Binding)"/>
|
||||
</node>
|
||||
<node COLOR="#77b3ba" CREATED="1696025158721" ID="ID_299445816" MODIFIED="1696025179668" TEXT="auch diesen Test kann man jetzt viel knapper schreiben">
|
||||
<icon BUILTIN="smiley-oh"/>
|
||||
</node>
|
||||
<node COLOR="#435e98" CREATED="1696023965128" ID="ID_300657180" MODIFIED="1696025025547" TEXT="besser explizit den bool-Wert in den Main-Thread bringen">
|
||||
<icon BUILTIN="idea"/>
|
||||
<node CREATED="1696023991959" ID="ID_1226872902" MODIFIED="1696024013956" TEXT="jetzt wo wir das so ganz locker können">
|
||||
<icon BUILTIN="ksmiletris"/>
|
||||
</node>
|
||||
<node CREATED="1696024808008" ID="ID_609747317" MODIFIED="1696025021431" TEXT="zirkulärer Bezug ⟹ template parameter deduction unmöglich">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...das ist <i>interessant,</i> aber nicht kritisch; und zwar weil ich den Test jetzt umgeschrieben habe auf ein Lambda, und gar keine eigenständige Klasse mehr verwende — viel spannender ist, daß der C++ - Compiler überhaupt schafft, solchen Code zu „knacken“
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1696025030399" ID="ID_838223706" MODIFIED="1696025042055" TEXT="auch geprüft daß es funktioniert (mal die Logik umgedreht)">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1695394753483" FOLDED="true" ID="ID_1338410455" MODIFIED="1695584550744" TEXT="SyncBarrier_test">
|
||||
|
|
|
|||
Loading…
Reference in a new issue