r6.1.0:LFDS610_BARRIER_COMPILER_FULL

From liblfds.org
Revision as of 14:07, 4 January 2015 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source File

/liblfds610/inc/liblfds610.h

Define

#define LFDS610_BARRIER_COMPILER_FULL  [compiler full compiler barrier directive]

Parameters

No parameters.

Return Value

No return value.

Notes

Compilers typically are able to re-order the flow of instructions, where this re-ordering is only guaranteed to be valid within the context of a single thread; e.g. if thread A performs an operation and then raises a flag, where thread B is waiting on the flag, the compiler will in its re-ordering only take into account that the behaviour of the thread being re-ordered remains valid, such that in this case we might see in thread A the flag being raised before the operation is performed, since the compiler isn't taking into account that thread B is written on the assumption the flag will be raised after the operation.

Compilers typically offer a directive which acts as a full compiler barrier, where a full compiler barrier the prevents the compiler re-ordering both load and store operations below the barrier above the barrier and prevents the compiler re-ordering load and store operations above the barrier to below the barrier.

Examples

Under MSVC, there is a compiler intrinsic _ReadWriteBarrier(), which has the following prototype;

void _ReadWriteBarrier(void);

As such, the implementation of LFDS610_BARRIER_COMPILER_FULL on MSVC looks like this;

#define LFDS610_BARRIER_PROCESSOR_FULL  _ReadWriteBarrier()

Note there is no trailing semi-colon. It is however harmless to have it in the #define.

See Also