Namespaces

Enumerations

enum SyncOpt
Name Value
AcqRelOps 0
Fence 1
None 2

An enumeration of various synchronization options to use when performing

memory transfer operations with WellDefinedCopy(To|From).

:: AcqRelOps ::

Use either memory_order_acquire (CopyFrom) or memory_order_release (CopyTo)

on every atomic load/store operation during the transfer to/from the shared

buffer.

:: Fence ::

Use either a memory_order_acquire thread fence (CopyFrom) after the transfer

operation, or a memory_order_release (CopyTo) thread fence before the

operation, and memory_order_relaxed for each of the atomic load/store

operations during the transfer.

:: None ::

Simply use memory_order_relaxed for each of the atomic load/store

operations during the transfer. Do not actually introduce any

explicit synchronization behavior.

WARNING: Use cases for this transfer mode tend to unusual. Users will almost

always want some form of synchronization to take place during their

transfers. One example of where it may be appropriate to use SyncOpt::None

might be a situation where users are attempting to observe the state of more

than one object while inside of a sequence lock read transaction, and the

user has decided that it is better to use a thread fence than to use acquire

semantics on each element transferred. Such a sequence might look something

like this:

Foo foo1, foo2;

Bar bar1, bar2;

...

WellDefinedCopyFrom

<SyncOpt

::None, alignof(Foo)>(

&foo

1,

&src

_foo1, sizeof(foo1));

WellDefinedCopyFrom

<SyncOpt

::None, alignof(Foo)>(

&foo

2,

&src

_foo2, sizeof(foo2));

WellDefinedCopyFrom

<SyncOpt

::None, alignof(Foo)>(

&bar

1,

&src

_bar1, sizeof(bar1));

WellDefinedCopyFrom

<SyncOpt

::Fence, alignof(Foo)>(

&bar

2,

&src

_bar2, sizeof(bar2));

Note that it is the _last_ transfer operation which includes the fence. In

the case of a CopyTo operation (when publishing data) it would be the _first_

operation which included the fence, not the last.

Defined at line 54 of file ../../zircon/system/ulib/concurrent/include/lib/concurrent/common.h

Records

Functions

  • template <typename Transaction>
    ChainLockGuard<Transaction> <deduction guide for ChainLockGuard> (ChainLock<Transaction> & )

    Deduction guides that allow the Transaction type to be deduced from the ChainLock instantiation

    passed to the constructor.

    Example:

    using MyChainLock = concurrent::ChainLock

    <MyTransaction

    >;

    using concurrent::ChainLockGuard;

    MyChainLock lock;

    ChainLockGuard guard{lock}; // Deduces ChainLockGuard

    <MyTransaction

    > from the lock argument.

  • template <typename Transaction>
    ChainLockGuard<Transaction> <deduction guide for ChainLockGuard> (ChainLock<Transaction> & lock, typename ChainLockGuard<Transaction>::AdoptTag )
  • template <typename Transaction>
    ChainLockGuard<Transaction> <deduction guide for ChainLockGuard> (ChainLock<Transaction> & lock, typename ChainLockGuard<Transaction>::DeferTag )
  • template <typename Transaction>
    ChainLockGuard<Transaction> <deduction guide for ChainLockGuard> (ChainLock<Transaction> & lock, typename ChainLockGuard<Transaction>::TakeTag )
  • template <SyncOpt kSyncOpt = SyncOpt::AcqRelOps, size_t kWorstCaseAlignment = 1>
    void WellDefinedCopyTo (void * dst, const void * src, size_t size_bytes)

    Copy |size_bytes| bytes from |src| to |dst| using atomic store operations to move

    the element into |dst| so that the behavior of the system is always well

    defined, even if there is a WellDefinedCopyFrom operation reading from the

    memory pointed to by |dst| concurrent with this CopyTo operation.

    WellDefinedCopyTo has memcpy semantics, not memmove semantics. In other

    words, it is illegal for |src| or |dst| to overlap in any way.

    While it is not required, by default, that |src| and |dst| have any specific

    alignment, both |src| and |dst| *must* have the _same_ alignment.

    IOW: (|src|

    &

    0x7) *must* equal (|dst|

    &

    0x7)

    :: Template Args ::

    |kSyncOpt|

    Controls the options for memory order synchronization. See the comments in

    lib/concurrent/common.h for details.

    |kWorstCaseAlignment|

    An explicit guarantee of the worst case alignment that |src|/|dst| will obey.

    When this alignment guarantee is greater than or equal to the maximum

    internal transfer granularity of 64 bits, the initial explicit alignment step

    of the operation can be optimized away for a minor performance gain.

    Defined at line 47 of file ../../zircon/system/ulib/concurrent/include/lib/concurrent/copy.h

  • template <SyncOpt kSyncOpt = SyncOpt::AcqRelOps, size_t kWorstCaseAlignment = 1>
    void WellDefinedCopyFrom (void * dst, const void * src, size_t size_bytes)

    Copy |size_bytes| bytes from |src| to |dst| using atomic load operations to load the

    element from |src| so that the behavior of the system is always well defined,

    even if there is a WellDefinedCopyTo operation writing to the memory pointed

    to by |src| concurrent with this CopyFrom operation.

    WellDefinedCopyFrom has memcpy semantics, not memmove semantics. In other

    words, it is illegal for |src| or |dst| to overlap in any way.

    While it is not required, by default, that |src| and |dst| have any specific

    alignment, both |src| and |dst| *must* have the _same_ alignment.

    IOW: (|src|

    &

    0x7) *must* equal (|dst|

    &

    0x7)

    :: Template Args ::

    |kSyncOpt|

    Controls the options for memory order synchronization. See the comments in

    lib/concurrent/common.h for details.

    |kWorstCaseAlignment|

    An explicit guarantee of the worst case alignment that |src|/|dst| will obey.

    When this alignment guarantee is greater than or equal to the maximum

    internal transfer granularity of 64 bits, the initial explicit alignment step

    of the operation can be optimized away for a minor performance gain.

    Defined at line 87 of file ../../zircon/system/ulib/concurrent/include/lib/concurrent/copy.h

  • template <typename Transaction>
    bool AcquireBothOrBackoff (ChainLock<Transaction> & firstChainLock<Transaction> & second)

    Utility to simplify expressions where two chain locks need to be acquired with backoff. Returns

    true if both locks where acquired or false if the current transaction needs to back off.

    Defined at line 405 of file ../../zircon/system/ulib/concurrent/include/lib/concurrent/chainlock.h