libpq: Add PQgetThreadLock() to mirror PQregisterThreadLock()
Jacob Champion <jchampion@postgresql.org>
Author:
Jacob Champion <jchampion@postgresql.org>
Date: 2026-03-05T18:04:48Z
Releases:
19 (unreleased)
libpq: Add PQgetThreadLock() to mirror PQregisterThreadLock()
Allow libpq clients to retrieve the current pg_g_threadlock pointer with
PQgetThreadLock(). Single-threaded applications could already do this in
a convoluted way:
pgthreadlock_t tlock;
tlock = PQregisterThreadLock(NULL);
PQregisterThreadLock(tlock); /* re-register the callback */
/* use tlock */
But a generic library can't do that without potentially breaking
concurrent libpq connections.
The motivation for doing this now is the libpq-oauth plugin, which
currently relies on direct injection of pg_g_threadlock, and should
ideally not.
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAOYmi%2BmEU_q9sr1PMmE-4rLwFN%3DOjyndDwFZvpsMU3RNJLrM9g%40mail.gmail.com
Discussion: https://postgr.es/m/CAOYmi%2B%3DMHD%2BWKD4rsTn0v8220mYfyLGhEc5EfhmtqrAb7SmC5g%40mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/libpq.sgml | modified | +5 −1 |
| src/interfaces/libpq/exports.txt | modified | +1 −0 |
| src/interfaces/libpq/fe-connect.c | modified | +7 −0 |
| src/interfaces/libpq/libpq-fe.h | modified | +8 −2 |
Discussion
- [oauth] Stabilize the libpq-oauth ABI (and allow alternative implementations?) 28 messages · 2025-12-09 → 2026-03-31
- [PATCH] Add PQgetThreadLock() to expose the Kerberos/Curl mutex 6 messages · 2026-02-27 → 2026-03-06