Skip to content

Commit 1b83b97

Browse files
committed
Fix Windows build, remove some warnings, try to fix atomic alignment issues on Win32
1 parent 1c87dfa commit 1b83b97

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

engine.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ ptrackMapInit(void)
253253
}
254254
else
255255
{
256-
strncat(ptrack_map->magic, PTRACK_MAGIC, 3);
256+
memcpy(ptrack_map->magic, PTRACK_MAGIC, PTRACK_MAGIC_SIZE);
257257
ptrack_map->version_num = PTRACK_VERSION_NUM;
258258
}
259259

@@ -639,9 +639,13 @@ ptrack_mark_block(RelFileNodeBackend smgr_rnode,
639639
{
640640
size_t hash;
641641
XLogRecPtr new_lsn;
642-
XLogRecPtr old_lsn;
643-
XLogRecPtr old_init_lsn;
644642
PtBlockId bid;
643+
/*
644+
* We use pg_atomic_uint64 here only for alignment purposes, because
645+
* pg_atomic_uint64 is forcely aligned on 8 bytes during the MSVC build.
646+
*/
647+
pg_atomic_uint64 old_lsn;
648+
pg_atomic_uint64 old_init_lsn;
645649

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

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

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

665-
if (old_init_lsn == InvalidXLogRecPtr)
669+
if (old_init_lsn.value == InvalidXLogRecPtr)
666670
{
667-
elog(DEBUG1, "ptrack_mark_block: init_lsn " UINT64_FORMAT " <- " UINT64_FORMAT, old_init_lsn, new_lsn);
671+
elog(DEBUG1, "ptrack_mark_block: init_lsn " UINT64_FORMAT " <- " UINT64_FORMAT, old_init_lsn.value, new_lsn);
668672

669-
while (old_init_lsn < new_lsn &&
670-
!pg_atomic_compare_exchange_u64(&ptrack_map->init_lsn, &old_init_lsn, new_lsn));
673+
while (old_init_lsn.value < new_lsn &&
674+
!pg_atomic_compare_exchange_u64(&ptrack_map->init_lsn, (uint64 *) &old_init_lsn.value, new_lsn));
671675
}
672676

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

675679
/* Atomically assign new LSN value */
676-
while (old_lsn < new_lsn &&
677-
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[hash], &old_lsn, new_lsn));
680+
while (old_lsn.value < new_lsn &&
681+
!pg_atomic_compare_exchange_u64(&ptrack_map->entries[hash], (uint64 *) &old_lsn.value, new_lsn));
678682
elog(DEBUG3, "ptrack_mark_block: map[%zu]=" UINT64_FORMAT, hash, pg_atomic_read_u64(&ptrack_map->entries[hash]));
679683
}
680684
}

engine.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333

3434
#define PTRACK_BUF_SIZE 1000
3535

36+
/* Ptrack magic bytes */
37+
#define PTRACK_MAGIC "ptk"
38+
#define PTRACK_MAGIC_SIZE 4
39+
3640
/*
3741
* Header of ptrack map.
3842
*/
@@ -42,7 +46,7 @@ typedef struct PtrackMapHdr
4246
* Three magic bytes (+ \0) to be sure, that we are reading ptrack.map
4347
* with a right PtrackMapHdr strucutre.
4448
*/
45-
char magic[4];
49+
char magic[PTRACK_MAGIC_SIZE];
4650

4751
/*
4852
* Value of PTRACK_VERSION_NUM at the time of map initialization.

patches/REL_12_STABLE-ptrack-core.diff

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ index 050cee5f9a9..75cf67d464f 100644
8585

8686
/*
8787
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
88-
index 705f229b27f..bec4af88810 100644
88+
index aff3e885f36..4fffa5df17c 100644
8989
--- a/src/backend/storage/sync/sync.c
9090
+++ b/src/backend/storage/sync/sync.c
9191
@@ -75,6 +75,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */
@@ -97,7 +97,7 @@ index 705f229b27f..bec4af88810 100644
9797
/* Intervals for calling AbsorbSyncRequests */
9898
#define FSYNCS_PER_ABSORB 10
9999
#define UNLINKS_PER_ABSORB 10
100-
@@ -418,6 +420,9 @@ ProcessSyncRequests(void)
100+
@@ -420,6 +422,9 @@ ProcessSyncRequests(void)
101101
CheckpointStats.ckpt_longest_sync = longest;
102102
CheckpointStats.ckpt_agg_sync_time = total_elapsed;
103103

@@ -224,6 +224,37 @@ index 56f83d2fb2f..60bb7bf7a3b 100644
224224
/* end of list */
225225
{NULL, false}
226226
};
227+
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
228+
index 61a24c2e3c6..cbd46d0cb02 100644
229+
--- a/src/include/miscadmin.h
230+
+++ b/src/include/miscadmin.h
231+
@@ -369,7 +369,7 @@ typedef enum ProcessingMode
232+
NormalProcessing /* normal processing */
233+
} ProcessingMode;
234+
235+
-extern ProcessingMode Mode;
236+
+extern PGDLLIMPORT ProcessingMode Mode;
237+
238+
#define IsBootstrapProcessingMode() (Mode == BootstrapProcessing)
239+
#define IsInitProcessingMode() (Mode == InitProcessing)
240+
diff --git a/src/include/port/pg_crc32c.h b/src/include/port/pg_crc32c.h
241+
index fbd079d2439..01682035e0b 100644
242+
--- a/src/include/port/pg_crc32c.h
243+
+++ b/src/include/port/pg_crc32c.h
244+
@@ -69,8 +69,11 @@ extern pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t le
245+
#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF)
246+
247+
extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len);
248+
-extern pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len);
249+
-
250+
+extern
251+
+#ifndef FRONTEND
252+
+PGDLLIMPORT
253+
+#endif
254+
+pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len);
255+
#ifdef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
256+
extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void *data, size_t len);
257+
#endif
227258
diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
228259
index 525cc6203e1..9481e1c5a88 100644
229260
--- a/src/include/storage/copydir.h

ptrack.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#define PTRACK_VERSION "2.1"
2626
/* Ptrack version as a number */
2727
#define PTRACK_VERSION_NUM 210
28-
/* Ptrack magic bytes */
29-
#define PTRACK_MAGIC "ptk"
3028

3129
/*
3230
* Structure identifying block on the disk.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy