Relax LazyDataObject.augmentations() implementation 69/76969/7
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 13 Oct 2018 09:35:56 +0000 (11:35 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Mon, 15 Oct 2018 12:14:57 +0000 (12:14 +0000)
commit6379e438ee4c8496c7d71865b1a29409dcd06d7b
tree73ff67995365dcb574cfca5fb18fed0c84184e3a
parent2b5988887490b942f1c9978f6792f5b93980afb6
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>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyDataObject.java