Library: add shortcut-ctor for own-member function
A common usage pattern is to derive from lib::Thread and then implement the actual thread function as a member function of this special-Thread-object (possibly also involving other data members) Provide a simplified invocation for this special case, also generating the thread-id automatically from the arguments
This commit is contained in:
parent
2c18c39c18
commit
691d2b43fa
3 changed files with 71 additions and 3 deletions
|
|
@ -108,6 +108,7 @@
|
|||
#include "lib/nocopy.hpp"
|
||||
#include "include/logging.h"
|
||||
#include "lib/meta/function.hpp"
|
||||
#include "lib/format-util.hpp"
|
||||
#include "lib/result.hpp"
|
||||
|
||||
#include <thread>
|
||||
|
|
@ -302,6 +303,13 @@ namespace lib {
|
|||
, std::forward<ARGS> (args)... }
|
||||
{ }
|
||||
|
||||
template<class SUB, typename...ARGS>
|
||||
ThreadLifecycle (RES (SUB::*memFun) (ARGS...), ARGS&& ...args)
|
||||
: ThreadLifecycle{util::joinArgList (lib::meta::typeStr<SUB>(), args...)
|
||||
,std::move (memFun)
|
||||
,static_cast<SUB*> (this)
|
||||
,std::forward<ARGS> (args)... }
|
||||
{ }
|
||||
};
|
||||
|
||||
}//(End)base implementation.
|
||||
|
|
|
|||
|
|
@ -93,8 +93,7 @@ namespace lib {
|
|||
: Thread
|
||||
{
|
||||
TestThread()
|
||||
: Thread("test Thread creation",
|
||||
bind (&TestThread::theOperation, this, checksum.createVal(), checksum.createVal()))
|
||||
: Thread{&TestThread::theOperation, checksum.createVal(), checksum.createVal()}
|
||||
{ } // note the binding (functor object) is passed as anonymous temporary
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -79385,7 +79385,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node CREATED="1695607699183" ID="ID_470294434" MODIFIED="1695607712099" TEXT="Ctor-Varianten">
|
||||
<node CREATED="1695607713041" ID="ID_1988127528" MODIFIED="1695607720299" TEXT="ohne Thread-Kennung"/>
|
||||
<node CREATED="1695607745859" ID="ID_1296792416" MODIFIED="1695607796305" TEXT="direkt mit einem Member-Fun-Ptr">
|
||||
<node CREATED="1695607745859" ID="ID_1296792416" MODIFIED="1695915558180" TEXT="direkt mit einem Member-Fun-Ptr">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head/>
|
||||
<body>
|
||||
|
|
@ -79394,6 +79394,29 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<linktarget COLOR="#7898aa" DESTINATION="ID_1296792416" ENDARROW="Default" ENDINCLINATION="-613;39;" ID="Arrow_ID_1122896333" SOURCE="ID_1888383911" STARTARROW="None" STARTINCLINATION="88;-226;"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1695915569144" ID="ID_1968434740" MODIFIED="1695915583304" TEXT="auch die Thread-ID generieren">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1695915584543" ID="ID_1434344091" MODIFIED="1695915603355" TEXT="erste Fassung: joinArgList">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1695915605227" ID="ID_414676042" MODIFIED="1695915614639" TEXT="downcast von *this machen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#435e98" CREATED="1695915623001" ID="ID_284696799" MODIFIED="1695915685105" TEXT="keine weiteren compile-Time-Checks">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
das macht nur den Code komplex, macht aber die Diagnostik nicht besser; std::invoke hat bereits gute Diagnostik (man muß sie nur lesen können)
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -79841,6 +79864,13 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695394270093" ID="ID_585437655" MODIFIED="1695394271819" TEXT="ThreadWrapper_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1695911786871" ID="ID_1371513124" MODIFIED="1695911794232" TEXT="läuft nach Umstellung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1695915511991" ID="ID_1888383911" MODIFIED="1695915563604" TEXT="Ergänzung: Konstruktor für eigene Memberfunktion">
|
||||
<arrowlink COLOR="#7898aa" DESTINATION="ID_1296792416" ENDARROW="Default" ENDINCLINATION="-613;39;" ID="Arrow_ID_1122896333" STARTARROW="None" STARTINCLINATION="88;-226;"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1695394288052" ID="ID_1407826381" MODIFIED="1695395666211" TEXT="Kritik: der testet nicht punktgenau">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head/>
|
||||
|
|
@ -79861,6 +79891,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695394665822" ID="ID_881973960" MODIFIED="1695394668399" TEXT="ThreadWrapperJoin_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1695911786871" ID="ID_1004221223" MODIFIED="1695911801372" TEXT="läuft nach Umstellung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node CREATED="1695394703974" ID="ID_1918931115" MODIFIED="1695394714328" TEXT="erscheint bereits adäquat">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
|
|
@ -79870,6 +79903,25 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695394744028" ID="ID_1755648327" MODIFIED="1695394746744" TEXT="ThreadWrapperSelfRecognitionTest_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#e0ceaa" COLOR="#690f14" CREATED="1695911804614" ID="ID_174546781" MODIFIED="1695911929623" TEXT="Scheitert mit Fehler">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
<font face="Monospaced" size="2">### Lumiera halted due to an unexpected Error ### </font>
|
||||
</p>
|
||||
<p>
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<font face="Monospaced" size="2">+++ Caught Exception LUMIERA_ERROR_INVALID:invalid input or parameters </font>
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="broken-line"/>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1695394753483" FOLDED="true" ID="ID_1338410455" MODIFIED="1695584550744" TEXT="SyncBarrier_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
|
|
@ -80231,12 +80283,21 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1695511970250" ID="ID_1548667731" MODIFIED="1695512067599" TEXT="SyncLocking_test ">
|
||||
<linktarget COLOR="#7788a3" DESTINATION="ID_1548667731" ENDARROW="Default" ENDINCLINATION="-97;-50;" ID="Arrow_ID_1461533786" SOURCE="ID_1181374984" STARTARROW="None" STARTINCLINATION="-396;62;"/>
|
||||
<icon BUILTIN="hourglass"/>
|
||||
<node COLOR="#338800" CREATED="1695911786871" ID="ID_1433073255" MODIFIED="1695911950387" TEXT="läuft nach Umstellung Thread-Wrapper">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1695511999172" ID="ID_1059124970" MODIFIED="1695512003054" TEXT="SyncClasslock_test">
|
||||
<icon BUILTIN="hourglass"/>
|
||||
<node COLOR="#338800" CREATED="1695911786871" ID="ID_915768766" MODIFIED="1695911950387" TEXT="läuft nach Umstellung Thread-Wrapper">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1695512017890" ID="ID_953669300" MODIFIED="1695512023779" TEXT="SyncWaiting_test">
|
||||
<icon BUILTIN="hourglass"/>
|
||||
<node COLOR="#338800" CREATED="1695911786871" ID="ID_622595151" MODIFIED="1695911950387" TEXT="läuft nach Umstellung Thread-Wrapper">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695679685747" ID="ID_1841477437" MODIFIED="1695681430475" TEXT="DiagnosticContext_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue