Commit graph

5309 commits

Author SHA1 Message Date
f05ec78e08 DI: benchmark Double-Checked-Locking with Mutex
This is essentially the solution we used since start of the Lumiera project.
This solution is not entirely correct in theory, because the assignment to the
instance pointer can be visible prior to releasing the Mutex -- so another thread
might see a partially initialised object
2018-03-24 11:02:44 +01:00
ff256d9e57 DI: benchmark naive lock protected access
...which gives us the dramatic numbers we'd expect.
Especially the multithreaded variant contends drastically
2018-03-24 11:02:43 +01:00
d2dababf5c DI: benchmark dependency-factory with unprotected lazy init
NOT threadsafe.
Indeed, crashed several times during the multithreaded benchmark runs
2018-03-24 08:29:39 +01:00
69f21d96af DI: prepare benchmark of reference cases
_not_ using the dependency factory, rather direct access

 - to a shared object in the enclosing stack frame
 - to a heap allocated existing object accessed through uniqe_ptr
2018-03-24 07:48:59 +01:00
685a9b84ee Library: replace boost::noncopyable by our own library solution
Benefits
 - get rid of yet another pervasive Boost dependency
 - define additional more fine grained policies (move only, clonable)
2018-03-24 05:35:13 +01:00
8cb67fd9fa Library: inline the thread operation when possible
The Lumiera thread-wrapper accepts the operation to be performed
within the new thread as a function object, function reference or lambda.
Some of these types can be directly instantiated in the threadMain
function, and thus possibly inlined altogether. This is especially
relevant for Lambdas. OTOH, we can not instantiate function references
or bound member functions; in those cases we fall back to using a
std::function object, possibly incurring heap allocations.
2018-03-24 02:19:49 +01:00
a19a79b611 Library: modernise thread invocation
the operation to run within the thread can be passed through as lambda;
and with the help of C++11 perfect forwarding we can get rid of the
temporary ThreadStartContext entirely, which removes a lot of
pass-through argument copying
2018-03-24 02:00:51 +01:00
31539f00c8 Library: a function for performing multithreaded microbenchmarks 2018-03-24 01:58:34 +01:00
3104016cf2 DI: set up framework for investigation of performance impact
We are about to switch to Double Checked Locking with C++11 atomics,
and we want some rough numbers regarding the Impact
2018-03-23 23:42:10 +01:00
364dcd5291 DI: verify and improve static sanity checks
esp. for subclass instance creation from within a lambda
2018-03-22 21:43:19 +01:00
d9af3abb0f DI: implement creating singleton from arbitrary (user provided) closure/functor/lambda
this is quite an ugly feature, but I couldn't come up with
any convincing argument *not* to implement it (and its low hanging fruit)
2018-03-22 06:53:56 +01:00
e74576f6b0 DI: pass-through arbitrary arguments for initialisation of a ServiceInstance
...this part is a no-brainer.
However, it is not clear yet if we can (and want to) do something similar for deferred (lazy) instance creation
2018-03-22 04:19:33 +01:00
5c39498929 DI: clean-up and document the TDD test
...written as byproduct from the reimplementation draft.

NOTE there is a quite similar test from 2013, DependencyFactory_test
For now I prefer to retain both, since the old one should just continue
to work with minor API adjustments (and thus prove this rewrite is a
drop-in replacement).

On the long run those two tests could be merged eventually...
2018-03-19 05:34:27 +01:00
83476b3ef1 DI: Reworked dependency-factory implementation draft complete -- move into library headers
This is a complete makeover of our lib::Depend and lib::DependencyFactory templates.
While retaining the basic idea, the configuration has been completely rewritten
to favour configuration at the point where a service is provided rather,
than at the point where a dependency is used.

Note: we use differently named headers, so the entire Lumiera
code base still uses the old implementation. Next step will be
to switch the tests (which should be drop-in)
2018-03-19 03:46:49 +01:00
957e7ff54c DI: extract testcode into new unit test 2018-03-19 03:46:43 +01:00
debd7c1797 DI: fix indentation
...want to retain the git history
2018-03-19 01:55:17 +01:00
f66d452c56 DI: refurbish internal access for the configuration handles
explicit friendship seems adequate here
DependInject<SRV> becomes more or less a hidden part of Depend<SRV>,
but I prefer to bundle all those quite technical details in a separate
header, and close to the usage
2018-03-19 01:14:52 +01:00
b776ce568f DI: fix inspiring Segfault
a bloody closure that bangs itself away....
2018-03-19 00:44:26 +01:00
f0c8928301 DI: draft implementation for testmock support 2018-03-19 00:05:02 +01:00
786f051132 DI: problem of misconfiguration for service access
This is a tricky problem an an immediate consequence of the dynamic configuration
favoured by this design. We avoid a centralised configuration and thus there
are no automatic rules to enforce consistency. It would thus be possible
to start using a dependency in singleton style, but to switch to service
style later, after the fact.

An attempt was made to prevent such a mismatch by static initialisiation;
basically the presence of any Depend<SRV>::ServiceInstance<X> would disable
any usage of Depend<SRV> in singleton style. However, such a mechanism
was found to be fragile at best. It seems more apropriate just to fail
when establishing a ServiceInstance on a dependency already actively in
use (and to lock usage after destroying the ServiceInstance).

This issue is considered rather an architectural one, which can not be
solved by any mechanism at implementation level ever
2018-03-18 17:19:30 +01:00
5516700523 DI: draft configuration for using a service implementation created elsewhere 2018-03-18 02:11:46 +01:00
9f93154f62 DI: draft configuration for using a subclass Singleton 2018-03-18 01:30:51 +01:00
e1ca9f447b DI: draft syntax for special dependency injection configuration 2018-03-18 00:57:25 +01:00
eebe31aa7e DI: change to heap allocation for singletons
up to now we used placement into a static buffer.
While this approach is somewhat cool, I can't see much practical benefit anymore,
given that we use an elaborate framework which rules out the use of Meyers Singleton.
And given that with C++11 we're able just to use std::unique_ptr to do all work.

Moreover, the intended configurability will become much simpler by relying
on a _closure_ to produce a heap-allocated instance for all cases likewise.

The only possible problem I can see is that critical infrastructure might
rely on failsafe creation of some singleton. Up to now this scenario
remains theoretical however
2018-03-17 23:41:56 +01:00
e393d44e92 DI: replace Meyers Singleton by an explicitly managed buffer
Meyers Singleton is elegant and fast and considered the default solution
However...

 - we want an "instance" pointer that can be rebound and reset,
   and thus we are forced to use an explicit Mutex and an atomic variable.
   And the situation is such that the optimiser can not detect/verify this usage
   and thus generates a spurious additional lock for Meyers Singleton

 - we want the option to destroy our singletons explicitly
 - we need to create an abstracted closure for the ctor invocation
 - we need a compiletime-branch to exclude code generation for invoking
   the ctor of an abstract baseclass or interface

All those points would be somehow manageable, but would counterfeit the
simplicity of Meyers Singleton
2018-03-17 17:30:28 +01:00
261049e04d DI: minimalistic design for service access
Problems:
 - using Meyers Singleton plus a ClassLock;
   This is wasteful, since the compiler will emit additional synchronisation
   and will likely not be able to detect the presence of our explicit locking guard

 - what happens if the Meyers Singleton can not even be instantiated, e.g. for
   an abstract baseclass? We are required to install an explicit subclass configuration
   in that case, but the compiler is not able to see this will happen, when just
   compiling the lib::Depend
2018-03-17 03:36:58 +01:00
28176c58ed DI: drafts towards a new dependency factory design 2018-03-16 03:57:02 +01:00
2bc6b398ea DI: thoughts regarding the design of the dependency configuration 2018-03-15 04:24:03 +01:00
533ed45d8b DI: expand the concept of our dependency factory to handle service instances (#1086)
Most dependencies within Lumiera are singletons and this approach remains adequate.
Singletons are not "EVIL" per se. But in some cases, there is an explicit
lifecycle, managed by some subsystem. E.g. some GUI services are only available
while the GTK event loop is running.

This special case can be integrated transparently into our lib::Depend<TY> front-end,
which defaults to creating a singleton otherwise.
2018-03-11 03:20:21 +01:00
9ca9b1b89a ViewSpec: clarify how the inline DSL spec is transformed into a rule set
several nested repackaging ctor calls here.
In the end, it's an UICoord array, which is moved into heap storage within the rules set
2018-03-05 00:56:43 +01:00
69f87e994c ViewSpec: decide how to cast the types for building the DSL
we'll use a typedef to represent the default case
and provide the level within the UI-Tree as template parameter for the generic case

This avoids wrapping each definition into a builder function, which will be
the same function for 99% of the cases, and it looks rather compact and natural
for the default case, while still retaining genericity.

Another alternative would have been to inject the Tree-level at the invocation;
but doing so feels more like magic for me.
2018-02-24 04:25:41 +01:00
41b8d12b66 ViewSpec: reconsider how to build and structure the DSL (#1126)
...in the light of all the foundation components and frameworks created meanwhile
2018-02-23 05:07:39 +01:00
b6360b2e9c LocationSolver: automatically inject persp(UIC_ELIDED) (closes #1128)
decided to add a very specific preprocessing here, to make the DSL notation more natural.
My guess is that most people won't spot the presence of this tiny bit of magic,
and it would be way more surprising to have rules like

UICoord::currentWindow().panel("viewer").create()

fail in most cases, simply because there is a wildcard on the perspective
and the panel viewer does not (yet) exist. In such a case, we now turn the
perspective into a "existential quantified" wildcard, which is treated as if
the actually existing element was written explicitly into the pattern.
2018-02-17 05:11:34 +01:00
0f26f1e0f4 LocationSolver: Documentation and clean-up (#1127) 2018-02-17 03:45:07 +01:00
da8fd6a031 LocationSolver: use the "elided" marker for realistic create rules
...actually just more test coverage,
the feature is already implemented.

What *could* be done though is to inject that UIC_ELIDED marker
on missing perspective specs in create clauses automatically...
2018-02-16 07:34:48 +01:00
e1dd88970c Library: enable the STL algorithms to work with "Lumiera Forward Iterators"
especially std::find is relevant here.
I consider this only a preliminary solution and need to think it over
more in detail. But, judging from the description given in

http://en.cppreference.com/w/cpp/iterator

and

http://en.cppreference.com/w/cpp/concept/InputIterator

...the standard concept of "input iterator" seems to be closest to our
own concept, albeit it requires things like post increment, and a
reference_type convertible to value_type -- requirements we do not
necessarily support with our more limited "Lumiera Forward Iterator"
2018-02-16 06:48:52 +01:00
66cd1fcea8 UI-Coordinates: fix insidious bug
util::contains used to pick the overload for strings,
i.e. it first converted the UI-Coordinates to diagnostic output format
and then searched that string for '*' to determine if the pattern is explicit

works as expected, but not what you'd intend....
...and breaks spectacularly once you search for something as innocuous as '.'
2018-02-16 06:41:42 +01:00
983c490644 LocationSolver: test coverage for existentially quantified elements (#1128)
...and again spotted some really insidious bugs
2018-02-16 06:37:43 +01:00
0b21e816e3 LocationSolver: implement support for elided elements (#1128)
when used in a pattern for matching against the UI tree,
an element marked as UIC_ELIDED = "." is treated as existentially quantified.

This means, we assume / verify there *is* an element at that level,
but we do not care about what this element actually is. Within the
implementation, the handling is similar to a wildcard, yet such a
spec is not classified as a wildcard (it *is* an explicit element,
just not explicitly named).

The relevant consequence is that such an element matches at a leaf
position, while match on wildcards on leaf positions is prohibited,
to prevent arbitrary and nonsensical wildcard matches against
open ended patterns. Especially we need such an existential pattern
to express a rule to create elements from scratch, but within a
specific window with arbitrary (but existing) perspective.
2018-02-16 06:35:26 +01:00
6665fb68d6 LocationSolver: decide not to implement match based on context (#1130)
This looks like YAGNI, and it would be non trivial to implement.
But since the feature looks important for slick UI behaviour,
I've made a new ticket and leave it for now
2018-02-16 03:24:37 +01:00
f3791297d6 LocationSolver: cover most standard usage situations
with the exception of some special situations,
which require additional features from the engine,
especially binding-on-context

Not sure though if I'll implement these or say YAGNI
2018-02-16 01:59:51 +01:00
60d40a6a6e LocationSolver: concept for standard usage situation test coverage
...using a fixed set of rules this time,
while injecting a different (simulated) UI tree for each testcase
2018-02-14 04:42:19 +01:00
98cab32a08 LocationSolver: several rule match test cases 2018-02-14 03:02:44 +01:00
9249c513a9 LocationSolver: wildcard match test cases 2018-02-13 03:13:53 +01:00
92bf317d29 LocationSolver: long explicit path test cases
...and here a bug was hiding. gotcha
2018-02-13 02:46:43 +01:00
9fe314ad04 LocationSolver: testcases regarding perspective
TODO support for existentially quantified perspective to match against
"just the" perspectice, disregarding the actual value
2018-02-13 02:26:03 +01:00
c11e557b45 LocationSolver: smallest possible query test cases
querying on window level (=root level)
2018-02-11 04:36:11 +01:00
e04f61fe0d LocationSolver: length discriminating test cases 2018-02-11 04:16:58 +01:00
820abe2bef LocationSolver: provide DSL notation to write "create clauses" 2018-02-11 04:00:59 +01:00
7a167c4c3a LocationSolver: draft pattern for writing those test cases
...which shows: we also need a DSL mechanism for writing "create clauses"
2018-02-11 02:34:56 +01:00