postgres.git / summary / log / commit / refs
commit 9403b87c0010a6d9b88a880ae14dec48b4e30cc3
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sun Oct 25 22:18:30 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0
Fix "variable set but not used" warning with unnamed POSIX semaphores.
Late-model clang is able to notice, when building posix_sema.c with
USE_NAMED_POSIX_SEMAPHORES not defined, that the static variable
nextSemKey is set once and read nowhere. Rearrange the #ifdef's
to not declare or set it unless USE_NAMED_POSIX_SEMAPHORES. As a
small side benefit, we can skip a stat() call altogether if we're
not going to need it to initialize this variable, which I think
clarifies the code a fraction.
Per buildfarm member fritillary.
src/backend/port/posix_sema.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/backend/port/posix_sema.c b/src/backend/port/posix_sema.c
index 315ed16b197..77dbc586c1e 100644
--- a/src/backend/port/posix_sema.c
+++ b/src/backend/port/posix_sema.c
@@ -65,7 +65,10 @@ static PGSemaphore sharedSemas; /* array of PGSemaphoreData in shared memory */
#endif
static int numSems; /* number of semas acquired so far */
static int maxSems; /* allocated size of above arrays */
+
+#ifdef USE_NAMED_POSIX_SEMAPHORES
static int nextSemKey; /* next name to try */
+#endif
static void ReleaseSemaphores(int status, Datum arg);
@@ -195,6 +198,7 @@ PGSemaphoreShmemSize(int maxSemas)
void
PGReserveSemaphores(int maxSemas)
{
+#ifdef USE_NAMED_POSIX_SEMAPHORES
struct stat statbuf;
/*
@@ -208,6 +212,8 @@ PGReserveSemaphores(int maxSemas)
(errcode_for_file_access(),
errmsg("could not stat data directory \"%s\": %m",
DataDir)));
+ nextSemKey = statbuf.st_ino;
+#endif
#ifdef USE_NAMED_POSIX_SEMAPHORES
mySemPointers = (sem_t **) malloc(maxSemas * sizeof(sem_t *));
@@ -226,7 +232,6 @@ PGReserveSemaphores(int maxSemas)
numSems = 0;
maxSems = maxSemas;
- nextSemKey = statbuf.st_ino;
on_shmem_exit(ReleaseSemaphores, 0);
}
[parent: 3bd5a4755839]