Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3179701

Browse files
Convert archiver's force_dir_scan variable to an atomic variable.
Commitbd5132d introduced new atomic read/write functions withfull barrier semantics, which are intended to simplify convertingnon-performance-critical code to use atomic variables. This commitdemonstrates one such conversion.Reviewed-by: Yong LiDiscussion:https://postgr.es/m/20231110205128.GB1315705%40nathanxps13
1 parentbd5132d commit3179701

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

‎src/backend/postmaster/pgarch.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include"storage/proc.h"
4646
#include"storage/procsignal.h"
4747
#include"storage/shmem.h"
48-
#include"storage/spin.h"
4948
#include"utils/guc.h"
5049
#include"utils/memutils.h"
5150
#include"utils/ps_status.h"
@@ -83,11 +82,9 @@ typedef struct PgArchData
8382
intpgprocno;/* pgprocno of archiver process */
8483

8584
/*
86-
* Forces a directory scan in pgarch_readyXlog(). Protected by arch_lck.
85+
* Forces a directory scan in pgarch_readyXlog().
8786
*/
88-
boolforce_dir_scan;
89-
90-
slock_tarch_lck;
87+
pg_atomic_uint32force_dir_scan;
9188
}PgArchData;
9289

9390
char*XLogArchiveLibrary="";
@@ -174,7 +171,7 @@ PgArchShmemInit(void)
174171
/* First time through, so initialize */
175172
MemSet(PgArch,0,PgArchShmemSize());
176173
PgArch->pgprocno=INVALID_PGPROCNO;
177-
SpinLockInit(&PgArch->arch_lck);
174+
pg_atomic_init_u32(&PgArch->force_dir_scan,0);
178175
}
179176
}
180177

@@ -545,18 +542,12 @@ pgarch_readyXlog(char *xlog)
545542
charXLogArchiveStatusDir[MAXPGPATH];
546543
DIR*rldir;
547544
structdirent*rlde;
548-
boolforce_dir_scan;
549545

550546
/*
551547
* If a directory scan was requested, clear the stored file names and
552548
* proceed.
553549
*/
554-
SpinLockAcquire(&PgArch->arch_lck);
555-
force_dir_scan=PgArch->force_dir_scan;
556-
PgArch->force_dir_scan= false;
557-
SpinLockRelease(&PgArch->arch_lck);
558-
559-
if (force_dir_scan)
550+
if (pg_atomic_exchange_u32(&PgArch->force_dir_scan,0)==1)
560551
arch_files->arch_files_size=0;
561552

562553
/*
@@ -707,9 +698,7 @@ ready_file_comparator(Datum a, Datum b, void *arg)
707698
void
708699
PgArchForceDirScan(void)
709700
{
710-
SpinLockAcquire(&PgArch->arch_lck);
711-
PgArch->force_dir_scan= true;
712-
SpinLockRelease(&PgArch->arch_lck);
701+
pg_atomic_write_membarrier_u32(&PgArch->force_dir_scan,1);
713702
}
714703

715704
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp