Use "(void)" to mark pgstat_lock_entry(..., false) calls.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 6 Apr 2025 15:37:09 +0000 (11:37 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 6 Apr 2025 15:37:09 +0000 (11:37 -0400)
This should silence Coverity's complaints about the result being
sometimes ignored.

I'm inclined to think that these routines are simply misdesigned,
because sometimes it's okay to ignore the result and sometimes it
isn't, and we have no way to enforce the latter.  But for now
I just added a comment.

src/backend/utils/activity/pgstat.c
src/backend/utils/activity/pgstat_database.c
src/backend/utils/activity/pgstat_shmem.c

index 0005021f644b2e96ad97247078de25d5af85500b..21bdff106a937fb46b3d514a07f5b8c7e70dd000 100644 (file)
@@ -1019,7 +1019,7 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
        stats_data = MemoryContextAlloc(pgStatLocal.snapshot.context,
                                        kind_info->shared_data_len);
 
-   pgstat_lock_entry_shared(entry_ref, false);
+   (void) pgstat_lock_entry_shared(entry_ref, false);
    memcpy(stats_data,
           pgstat_get_entry_data(kind, entry_ref->shared_stats),
           kind_info->shared_data_len);
index fbaf83641170da250e8574a8a201e04f001539af..52d82d25352d0fd95f832569c43b2918bdb2d4be 100644 (file)
@@ -195,7 +195,7 @@ pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount)
        return;
    }
 
-   pgstat_lock_entry(entry_ref, false);
+   (void) pgstat_lock_entry(entry_ref, false);
 
    sharedent = (PgStatShared_Database *) entry_ref->shared_stats;
    sharedent->stats.checksum_failures += failurecount;
index 5cd243037551ce7ca954a2702f22863121321f44..2e33293b000977463bb391af0deb89efe1509230 100644 (file)
@@ -643,6 +643,13 @@ pgstat_release_entry_ref(PgStat_HashKey key, PgStat_EntryRef *entry_ref,
        pfree(entry_ref);
 }
 
+/*
+ * Acquire exclusive lock on the entry.
+ *
+ * If nowait is true, it's just a conditional acquire, and the result
+ * *must* be checked to verify success.
+ * If nowait is false, waits as necessary, always returning true.
+ */
 bool
 pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
 {
@@ -656,8 +663,10 @@ pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
 }
 
 /*
+ * Acquire shared lock on the entry.
+ *
  * Separate from pgstat_lock_entry() as most callers will need to lock
- * exclusively.
+ * exclusively.  The wait semantics are identical.
  */
 bool
 pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait)