diff --git a/src/backend/port/atomics.c b/src/backend/port/atomics.c index 3350fb7df301d041c4e26132f8c2a2a609386a05..439b3c18c7b26ad3aa062bf1ca3cbac00b0b1438 100644 --- a/src/backend/port/atomics.c +++ b/src/backend/port/atomics.c @@ -20,15 +20,32 @@ */ #define ATOMICS_INCLUDE_DEFINITIONS +#include "miscadmin.h" #include "port/atomics.h" #include "storage/spin.h" +#ifdef PG_HAVE_MEMORY_BARRIER_EMULATION +#ifdef WIN32 +#error "barriers are required (and provided) on WIN32 platforms" +#endif +#include <sys/types.h> +#include <signal.h> +#endif + #ifdef PG_HAVE_MEMORY_BARRIER_EMULATION void pg_spinlock_barrier(void) { - S_LOCK(&dummy_spinlock); - S_UNLOCK(&dummy_spinlock); + /* + * NB: we have to be reentrant here, some barriers are placed in signal + * handlers. + * + * We use kill(0) for the fallback barrier as we assume that kernels on + * systems old enough to require fallback barrier support will include an + * appropriate barrier while checking the existence of the postmaster + * pid. + */ + (void) kill(PostmasterPid, 0); } #endif