BufferProvider: improve configuration of thread-local dispatch
Since thread_local implies a static setup, we need a way how to build a new service instance. Usually this would be a default construction, yet there might be services with special init requirements. Using an explicit template parameter for this setup configuration allows to make the primary template parameter just the service itself, which makes the default usage much clearer.
This commit is contained in:
parent
a06ef95e94
commit
9bd3e550dc
3 changed files with 56 additions and 15 deletions
|
|
@ -41,22 +41,29 @@
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
namespace lib {
|
||||||
|
|
||||||
|
/** Extension point for LocalSlice: Service initialisation */
|
||||||
|
template<class SRV>
|
||||||
|
struct LocalSlice_DefaultSetup
|
||||||
|
{
|
||||||
|
using Service = SRV;
|
||||||
|
static Service init() { return Service(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common access point to thread-local service instances.
|
* Common access point to thread-local service instances.
|
||||||
* @tparam CONF static config / setup to initialise the service.
|
* @tparam CONF setup to initialise the service.
|
||||||
*/
|
*/
|
||||||
template<class CONF>
|
template<class SRV, class CONF =LocalSlice_DefaultSetup<SRV>>
|
||||||
class LocalSlice
|
struct LocalSlice
|
||||||
{
|
{
|
||||||
using Service = CONF::Service;
|
|
||||||
|
|
||||||
public:
|
|
||||||
LocalSlice() = default;
|
LocalSlice() = default;
|
||||||
|
|
||||||
// using default copy/assignment
|
// using default copy/assignment
|
||||||
|
|
||||||
|
|
||||||
|
using Service = CONF::Service;
|
||||||
|
|
||||||
/** service access */
|
/** service access */
|
||||||
Service&
|
Service&
|
||||||
operator*() const
|
operator*() const
|
||||||
|
|
|
||||||
|
|
@ -57,14 +57,7 @@ namespace test {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DummySetup
|
using DummySlice = LocalSlice<DummyBackend>;
|
||||||
{
|
|
||||||
using Service = DummyBackend;
|
|
||||||
|
|
||||||
static Service init() { return Service(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
using DummySlice = LocalSlice<DummySetup>;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -144308,6 +144308,47 @@ StM_bind(Builder<R1> b1, Extension<R1,R2> extension)
|
||||||
<node CREATED="1776474854867" ID="ID_1487038882" MODIFIED="1776474859837" TEXT="CONF">
|
<node CREATED="1776474854867" ID="ID_1487038882" MODIFIED="1776474859837" TEXT="CONF">
|
||||||
<node CREATED="1776474861216" ID="ID_399712480" MODIFIED="1776474870435" TEXT="typedef Service"/>
|
<node CREATED="1776474861216" ID="ID_399712480" MODIFIED="1776474870435" TEXT="typedef Service"/>
|
||||||
<node CREATED="1776474871327" ID="ID_142831800" MODIFIED="1776474879674" TEXT="eine init-Funktion"/>
|
<node CREATED="1776474871327" ID="ID_142831800" MODIFIED="1776474879674" TEXT="eine init-Funktion"/>
|
||||||
|
<node COLOR="#338800" CREATED="1776518244557" ID="ID_69243918" MODIFIED="1776522105417" TEXT="Verbesserung : Setup für Service-Typ">
|
||||||
|
<icon BUILTIN="button_ok"/>
|
||||||
|
<node CREATED="1776518286073" ID="ID_992160718" MODIFIED="1776518303060" TEXT="LocalSlice<SRV>"/>
|
||||||
|
<node CREATED="1776518303809" ID="ID_1039989287" MODIFIED="1776518323133" TEXT="normalerweise genügt ein default-Setup-Template"/>
|
||||||
|
<node COLOR="#435e98" CREATED="1776518324108" ID="ID_1914807086" MODIFIED="1776522047530" TEXT="explizite Spezialisierung soll möglich sein">
|
||||||
|
<icon BUILTIN="yes"/>
|
||||||
|
<node CREATED="1776521876873" ID="ID_1636226712" MODIFIED="1776522039333" TEXT="puh ... das wird in jedem Fall hässlich">
|
||||||
|
<richcontent TYPE="NOTE"><html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
man muß den aktuellen Namespace schließen, in lib gehen, dort die explizite Spezialisierung definieren...
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</richcontent>
|
||||||
|
<icon BUILTIN="smiley-angry"/>
|
||||||
|
</node>
|
||||||
|
<node CREATED="1776521934417" ID="ID_130169122" MODIFIED="1776522032176" TEXT="Lösung: 2.Template-Parameter mit Default-Init">
|
||||||
|
<icon BUILTIN="idea"/>
|
||||||
|
</node>
|
||||||
|
<node CREATED="1776521973780" ID="ID_1887344423" MODIFIED="1776522004871" TEXT="default ist dann LocalSlice_DefaultSetup<SRV>">
|
||||||
|
<richcontent TYPE="NOTE"><html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
direkt bei LocalSlice definiert; erzeugt eine default-konstruierte Instanz vom Service
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</richcontent>
|
||||||
|
</node>
|
||||||
|
<node COLOR="#338800" CREATED="1776522006689" ID="ID_1991943573" MODIFIED="1776522019517" TEXT="getested: Spezialisierung ist möglich">
|
||||||
|
<icon BUILTIN="button_ok"/>
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
</node>
|
</node>
|
||||||
<node COLOR="#338800" CREATED="1776474884669" ID="ID_66962199" MODIFIED="1776477543983" TEXT="LocalSlice_test">
|
<node COLOR="#338800" CREATED="1776474884669" ID="ID_66962199" MODIFIED="1776477543983" TEXT="LocalSlice_test">
|
||||||
<icon BUILTIN="button_ok"/>
|
<icon BUILTIN="button_ok"/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue