From: Tom Lane Date: Sun, 6 Apr 2025 15:37:09 +0000 (-0400) Subject: Use "(void)" to mark pgstat_lock_entry(..., false) calls. X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=2e4ccf1b4508cc337bb4d0afff1e32a049d549fc;p=users%2Frhaas%2Fpostgres.git Use "(void)" to mark pgstat_lock_entry(..., false) calls. 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. --- diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index 0005021f64..21bdff106a 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -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); diff --git a/src/backend/utils/activity/pgstat_database.c b/src/backend/utils/activity/pgstat_database.c index fbaf836411..52d82d2535 100644 --- a/src/backend/utils/activity/pgstat_database.c +++ b/src/backend/utils/activity/pgstat_database.c @@ -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; diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index 5cd2430375..2e33293b00 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -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)