Relax LazyDataObject.augmentations() implementation 92/76992/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 13 Oct 2018 09:35:56 +0000 (11:35 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 15 Oct 2018 13:14:18 +0000 (13:14 +0000)
commitb6e3e07fd29dc25fe4c4a0f0a09d8b1a62ab3fea
tree56f0408aa231b85494752682cc1233ba44d799b2
parentcd55e852848b6b5a21d54f153dbfa00e4974d3bc
Relax LazyDataObject.augmentations() implementation

We use double-checked locking to guard against concurrent
initialization of cachedAugmentations. While this ensures we do
not do the same work twice, it is a bit costly for the typical
case when the augmentations field is accessed once.

During the first call, we perform:
- a volatile read
- a lock acquire
- a volatile read
- compute the value (exclusive)
- a volatile write
- a lock release

Rather than doing that, allow the value to be computed concurrently
and use compare-and-swap to initialize it. Hence for the first call
we perform:
- a volatile read
- compute the value (concurrent)
- a compare-and-set

In case of concurrent initialization, all threads will compute
the value, but all except the first one will issue another volatile
read and throw their work away.

JIRA: MDSAL-377
Change-Id: I1dbf9c4e60cf9800720eea31bd9de936b1dae5aa
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 6379e438ee4c8496c7d71865b1a29409dcd06d7b)
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyDataObject.java