Skip to content

Commit

Permalink
Fix Windows build, remove some warnings, try to fix atomic alignment …
Browse files Browse the repository at this point in the history
…issues on Win32
  • Loading branch information
ololobus committed May 19, 2020
1 parent 1c87dfa commit 1b83b97
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
28 changes: 16 additions & 12 deletions engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ ptrackMapInit(void)
}
else
{
strncat(ptrack_map->magic, PTRACK_MAGIC, 3);
memcpy(ptrack_map->magic, PTRACK_MAGIC, PTRACK_MAGIC_SIZE);
ptrack_map->version_num = PTRACK_VERSION_NUM;
}

Expand Down Expand Up @@ -639,9 +639,13 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
{
size_t hash;
XLogRecPtr new_lsn;
XLogRecPtr old_lsn;
XLogRecPtr old_init_lsn;
PtBlockId bid;
/*
* We use pg_atomic_uint64 here only for alignment purposes, because
* pg_atomic_uint64 is forcely aligned on 8 bytes during the MSVC build.
*/
pg_atomic_uint64 old_lsn;
pg_atomic_uint64 old_init_lsn;

if (ptrack_map_size != 0 && (ptrack_map != NULL) &&
smgr_rnode.backend == InvalidBackendId) /* do not track temporary
Expand All @@ -657,24 +661,24 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
else
new_lsn = GetXLogInsertRecPtr();

old_lsn = pg_atomic_read_u64(&ptrack_map->entries[hash]);
old_lsn.value = pg_atomic_read_u64(&ptrack_map->entries[hash]);

/* Atomically assign new init LSN value */
old_init_lsn = pg_atomic_read_u64(&ptrack_map->init_lsn);
old_init_lsn.value = pg_atomic_read_u64(&ptrack_map->init_lsn);

if (old_init_lsn == InvalidXLogRecPtr)
if (old_init_lsn.value == InvalidXLogRecPtr)
{
elog(DEBUG1, "ptrack_mark_block: init_lsn " UINT64_FORMAT " <- " UINT64_FORMAT, old_init_lsn, new_lsn);
elog(DEBUG1, "ptrack_mark_block: init_lsn " UINT64_FORMAT " <- " UINT64_FORMAT, old_init_lsn.value, new_lsn);

while (old_init_lsn < new_lsn &&
!pg_atomic_compare_exchange_u64(&ptrack_map->init_lsn, &old_init_lsn, new_lsn));
while (old_init_lsn.value < new_lsn &&
!pg_atomic_compare_exchange_u64(&ptrack_map->init_lsn, (uint64 *) &old_init_lsn.value, new_lsn));
}

elog(DEBUG3, "ptrack_mark_block: map[%zu]=" UINT64_FORMAT " <- " UINT64_FORMAT, hash, old_lsn, new_lsn);
elog(DEBUG3, "ptrack_mark_block: map[%zu]=" UINT64_FORMAT " <- " UINT64_FORMAT, hash, old_lsn.value, new_lsn);

/* Atomically assign new LSN value */
while (old_lsn < new_lsn &&
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[hash], &old_lsn, new_lsn));
while (old_lsn.value < new_lsn &&
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[hash], (uint64 *) &old_lsn.value, new_lsn));
elog(DEBUG3, "ptrack_mark_block: map[%zu]=" UINT64_FORMAT, hash, pg_atomic_read_u64(&ptrack_map->entries[hash]));
}
}
6 changes: 5 additions & 1 deletion engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

#define PTRACK_BUF_SIZE 1000

/* Ptrack magic bytes */
#define PTRACK_MAGIC "ptk"
#define PTRACK_MAGIC_SIZE 4

/*
* Header of ptrack map.
*/
Expand All @@ -42,7 +46,7 @@ typedef struct PtrackMapHdr
* Three magic bytes (+ \0) to be sure, that we are reading ptrack.map
* with a right PtrackMapHdr strucutre.
*/
char magic[4];
char magic[PTRACK_MAGIC_SIZE];

/*
* Value of PTRACK_VERSION_NUM at the time of map initialization.
Expand Down
35 changes: 33 additions & 2 deletions patches/REL_12_STABLE-ptrack-core.diff
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ index 050cee5f9a9..75cf67d464f 100644

/*
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index 705f229b27f..bec4af88810 100644
index aff3e885f36..4fffa5df17c 100644
--- a/src/backend/storage/sync/sync.c
+++ b/src/backend/storage/sync/sync.c
@@ -75,6 +75,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */
Expand All @@ -97,7 +97,7 @@ index 705f229b27f..bec4af88810 100644
/* Intervals for calling AbsorbSyncRequests */
#define FSYNCS_PER_ABSORB 10
#define UNLINKS_PER_ABSORB 10
@@ -418,6 +420,9 @@ ProcessSyncRequests(void)
@@ -420,6 +422,9 @@ ProcessSyncRequests(void)
CheckpointStats.ckpt_longest_sync = longest;
CheckpointStats.ckpt_agg_sync_time = total_elapsed;

Expand Down Expand Up @@ -224,6 +224,37 @@ index 56f83d2fb2f..60bb7bf7a3b 100644
/* end of list */
{NULL, false}
};
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 61a24c2e3c6..cbd46d0cb02 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -369,7 +369,7 @@ typedef enum ProcessingMode
NormalProcessing /* normal processing */
} ProcessingMode;

-extern ProcessingMode Mode;
+extern PGDLLIMPORT ProcessingMode Mode;

#define IsBootstrapProcessingMode() (Mode == BootstrapProcessing)
#define IsInitProcessingMode() (Mode == InitProcessing)
diff --git a/src/include/port/pg_crc32c.h b/src/include/port/pg_crc32c.h
index fbd079d2439..01682035e0b 100644
--- a/src/include/port/pg_crc32c.h
+++ b/src/include/port/pg_crc32c.h
@@ -69,8 +69,11 @@ extern pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t le
#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF)

extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len);
-extern pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len);
-
+extern
+#ifndef FRONTEND
+PGDLLIMPORT
+#endif
+pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len);
#ifdef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void *data, size_t len);
#endif
diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
index 525cc6203e1..9481e1c5a88 100644
--- a/src/include/storage/copydir.h
Expand Down
2 changes: 0 additions & 2 deletions ptrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#define PTRACK_VERSION "2.1"
/* Ptrack version as a number */
#define PTRACK_VERSION_NUM 210
/* Ptrack magic bytes */
#define PTRACK_MAGIC "ptk"

/*
* Structure identifying block on the disk.
Expand Down

0 comments on commit 1b83b97

Please sign in to comment.