Commit de6429a8 authored by Andres Freund's avatar Andres Freund

Provide a generic fallback for pg_compiler_barrier using an extern function.

If the compiler/arch combination does not provide compiler barriers,
provide a fallback. That fallback simply consists out of a function
call into a externally defined function.  That should guarantee
compiler barrierer semantics except for compilers that do inter
translation unit/global optimization - those better provide an actual
compiler barrier.

Hopefully this fixes Tom's report of linker failures due to
pg_compiler_barrier_impl not being provided.

I'm not backpatching this commit as it builds on the new atomics
infrastructure. If we decide an equivalent fix needs to be
backpatched, I'll do so in a separate commit.

Discussion: 27746.1420930690@sss.pgh.pa.us

Per report from Tom Lane.
parent db4ec2ff
...@@ -32,6 +32,14 @@ pg_spinlock_barrier(void) ...@@ -32,6 +32,14 @@ pg_spinlock_barrier(void)
} }
#endif #endif
#ifdef PG_HAVE_COMPILER_BARRIER_EMULATION
void
pg_extern_compiler_barrier(void)
{
/* do nothing */
}
#endif
#ifdef PG_HAVE_ATOMIC_FLAG_SIMULATION #ifdef PG_HAVE_ATOMIC_FLAG_SIMULATION
......
...@@ -35,6 +35,22 @@ extern void pg_spinlock_barrier(void); ...@@ -35,6 +35,22 @@ extern void pg_spinlock_barrier(void);
#define pg_memory_barrier_impl pg_spinlock_barrier #define pg_memory_barrier_impl pg_spinlock_barrier
#endif #endif
#ifndef pg_compiler_barrier_impl
/*
* If the compiler/arch combination does not provide compiler barriers,
* provide a fallback. That fallback simply consists out of a function call
* into a externally defined function. That should guarantee compiler barrier
* semantics except for compilers that do inter translation unit/global
* optimization - those better provide an actual compiler barrier.
*
* Using a native compiler barrier for sure is a lot faster than this...
*/
#define PG_HAVE_COMPILER_BARRIER_EMULATION
extern void pg_extern_compiler_barrier(void);
#define pg_compiler_barrier_impl pg_extern_compiler_barrier
#endif
/* /*
* If we have atomics implementation for this platform fall back to providing * If we have atomics implementation for this platform fall back to providing
* the atomics API using a spinlock to protect the internal state. Possibly * the atomics API using a spinlock to protect the internal state. Possibly
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment