mirror of
https://github.com/postgres/postgres.git
synced 2025-11-28 11:44:57 +03:00
C11 alignas instead of unions -- extended alignments
This replaces some uses of pg_attribute_aligned() with the standard alignas() for cases where extended alignment (larger than max_align_t) is required. This patch stipulates that all supported compilers must support alignments up to PG_IO_ALIGN_SIZE, but that seems pretty likely. We can then also desupport the case where direct I/O is disabled because pg_attribute_aligned is not supported. Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/46f05236-d4d4-4b4e-84d4-faa500f14691%40eisentraut.org
This commit is contained in:
@@ -1132,25 +1132,15 @@ typedef struct PGAlignedBlock
|
|||||||
* for I/O in general, but may be strictly required on some platforms when
|
* for I/O in general, but may be strictly required on some platforms when
|
||||||
* using direct I/O.
|
* using direct I/O.
|
||||||
*/
|
*/
|
||||||
typedef union PGIOAlignedBlock
|
typedef struct PGIOAlignedBlock
|
||||||
{
|
{
|
||||||
#ifdef pg_attribute_aligned
|
alignas(PG_IO_ALIGN_SIZE) char data[BLCKSZ];
|
||||||
pg_attribute_aligned(PG_IO_ALIGN_SIZE)
|
|
||||||
#endif
|
|
||||||
char data[BLCKSZ];
|
|
||||||
double force_align_d;
|
|
||||||
int64 force_align_i64;
|
|
||||||
} PGIOAlignedBlock;
|
} PGIOAlignedBlock;
|
||||||
|
|
||||||
/* Same, but for an XLOG_BLCKSZ-sized buffer */
|
/* Same, but for an XLOG_BLCKSZ-sized buffer */
|
||||||
typedef union PGAlignedXLogBlock
|
typedef struct PGAlignedXLogBlock
|
||||||
{
|
{
|
||||||
#ifdef pg_attribute_aligned
|
alignas(PG_IO_ALIGN_SIZE) char data[XLOG_BLCKSZ];
|
||||||
pg_attribute_aligned(PG_IO_ALIGN_SIZE)
|
|
||||||
#endif
|
|
||||||
char data[XLOG_BLCKSZ];
|
|
||||||
double force_align_d;
|
|
||||||
int64 force_align_i64;
|
|
||||||
} PGAlignedXLogBlock;
|
} PGAlignedXLogBlock;
|
||||||
|
|
||||||
/* msb for char */
|
/* msb for char */
|
||||||
|
|||||||
@@ -85,10 +85,9 @@ extern PGDLLIMPORT int max_safe_fds;
|
|||||||
* to the appropriate Windows flag in src/port/open.c. We simulate it with
|
* to the appropriate Windows flag in src/port/open.c. We simulate it with
|
||||||
* fcntl(F_NOCACHE) on macOS inside fd.c's open() wrapper. We use the name
|
* fcntl(F_NOCACHE) on macOS inside fd.c's open() wrapper. We use the name
|
||||||
* PG_O_DIRECT rather than defining O_DIRECT in that case (probably not a good
|
* PG_O_DIRECT rather than defining O_DIRECT in that case (probably not a good
|
||||||
* idea on a Unix). We can only use it if the compiler will correctly align
|
* idea on a Unix).
|
||||||
* PGIOAlignedBlock for us, though.
|
|
||||||
*/
|
*/
|
||||||
#if defined(O_DIRECT) && defined(pg_attribute_aligned)
|
#if defined(O_DIRECT)
|
||||||
#define PG_O_DIRECT O_DIRECT
|
#define PG_O_DIRECT O_DIRECT
|
||||||
#elif defined(F_NOCACHE)
|
#elif defined(F_NOCACHE)
|
||||||
#define PG_O_DIRECT 0x80000000
|
#define PG_O_DIRECT 0x80000000
|
||||||
|
|||||||
Reference in New Issue
Block a user