diff options
author | Andres Freund <andres@anarazel.de> | 2014-09-25 23:49:05 +0200 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2014-09-25 23:49:05 +0200 |
commit | b64d92f1a5602c55ee8b27a7ac474f03b7aee340 (patch) | |
tree | 2ac33fb70d31585297ae8baeb674ef757544a1d7 /src/include/c.h | |
parent | 9111d46351e8c3d82452a7454e43ccbf1991b3dc (diff) | |
download | postgresql-b64d92f1a5602c55ee8b27a7ac474f03b7aee340.tar.gz postgresql-b64d92f1a5602c55ee8b27a7ac474f03b7aee340.zip |
Add a basic atomic ops API abstracting away platform/architecture details.
Several upcoming performance/scalability improvements require atomic
operations. This new API avoids the need to splatter compiler and
architecture dependent code over all the locations employing atomic
ops.
For several of the potential usages it'd be problematic to maintain
both, a atomics using implementation and one using spinlocks or
similar. In all likelihood one of the implementations would not get
tested regularly under concurrency. To avoid that scenario the new API
provides a automatic fallback of atomic operations to spinlocks. All
properties of atomic operations are maintained. This fallback -
obviously - isn't as fast as just using atomic ops, but it's not bad
either. For one of the future users the atomics ontop spinlocks
implementation was actually slightly faster than the old purely
spinlock using implementation. That's important because it reduces the
fear of regressing older platforms when improving the scalability for
new ones.
The API, loosely modeled after the C11 atomics support, currently
provides 'atomic flags' and 32 bit unsigned integers. If the platform
efficiently supports atomic 64 bit unsigned integers those are also
provided.
To implement atomics support for a platform/architecture/compiler for
a type of atomics 32bit compare and exchange needs to be
implemented. If available and more efficient native support for flags,
32 bit atomic addition, and corresponding 64 bit operations may also
be provided. Additional useful atomic operations are implemented
generically ontop of these.
The implementation for various versions of gcc, msvc and sun studio have
been tested. Additional existing stub implementations for
* Intel icc
* HUPX acc
* IBM xlc
are included but have never been tested. These will likely require
fixes based on buildfarm and user feedback.
As atomic operations also require barriers for some operations the
existing barrier support has been moved into the atomics code.
Author: Andres Freund with contributions from Oskari Saarenmaa
Reviewed-By: Amit Kapila, Robert Haas, Heikki Linnakangas and Álvaro Herrera
Discussion: CA+TgmoYBW+ux5-8Ja=Mcyuy8=VXAnVRHp3Kess6Pn3DMXAPAEA@mail.gmail.com,
20131015123303.GH5300@awork2.anarazel.de,
20131028205522.GI20248@awork2.anarazel.de
Diffstat (limited to 'src/include/c.h')
-rw-r--r-- | src/include/c.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/include/c.h b/src/include/c.h index 2ceaaf6c1d7..ce38d78736f 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -582,6 +582,7 @@ typedef NameData *Name; #define AssertMacro(condition) ((void)true) #define AssertArg(condition) #define AssertState(condition) +#define AssertPointerAlignment(ptr, bndr) ((void)true) #define Trap(condition, errorType) #define TrapMacro(condition, errorType) (true) @@ -592,6 +593,7 @@ typedef NameData *Name; #define AssertMacro(p) ((void) assert(p)) #define AssertArg(condition) assert(condition) #define AssertState(condition) assert(condition) +#define AssertPointerAlignment(ptr, bndr) ((void)true) #else /* USE_ASSERT_CHECKING && !FRONTEND */ /* @@ -628,8 +630,15 @@ typedef NameData *Name; #define AssertState(condition) \ Trap(!(condition), "BadState") -#endif /* USE_ASSERT_CHECKING && !FRONTEND */ +/* + * Check that `ptr' is `bndr' aligned. + */ +#define AssertPointerAlignment(ptr, bndr) \ + Trap(TYPEALIGN(bndr, (uintptr_t)(ptr)) != (uintptr_t)(ptr), \ + "UnalignedPointer") + +#endif /* USE_ASSERT_CHECKING && !FRONTEND */ /* * Macros to support compile-time assertion checks. @@ -856,12 +865,22 @@ typedef NameData *Name; * The header must also declare the functions' prototypes, protected by * !PG_USE_INLINE. */ + +/* declarations which are only visible when not inlining and in the .c file */ #ifdef PG_USE_INLINE #define STATIC_IF_INLINE static inline #else #define STATIC_IF_INLINE #endif /* PG_USE_INLINE */ +/* declarations which are marked inline when inlining, extern otherwise */ +#ifdef PG_USE_INLINE +#define STATIC_IF_INLINE_DECLARE static inline +#else +#define STATIC_IF_INLINE_DECLARE extern +#endif /* PG_USE_INLINE */ + + /* ---------------------------------------------------------------- * Section 8: random stuff * ---------------------------------------------------------------- |