public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: [email protected]
Subject: pgsql: Clean up Windows-specific mutex code in libpq and ecpglib.
Date: Fri, 09 Feb 2024 16:21:22 +0000
Message-ID: <[email protected]> (raw)
Clean up Windows-specific mutex code in libpq and ecpglib.
Fix pthread-win32.h and pthread-win32.c to provide a more complete
emulation of POSIX pthread mutexes: define PTHREAD_MUTEX_INITIALIZER
and make sure that pthread_mutex_lock() can operate on a mutex
object that's been initialized that way. Then we don't need the
duplicative platform-specific logic in default_threadlock() and
pgtls_init(), which we'd otherwise need yet a third copy of for
an upcoming bug fix.
Also, since default_threadlock() supposes that pthread_mutex_lock()
cannot fail, try to ensure that that's actually true, by getting
rid of the malloc call that was formerly involved in initializing
an emulated mutex. We can define an extra state for the spinlock
field instead.
Also, replace the similar code in ecpglib/misc.c with this version.
While ecpglib's version at least had a POSIX-compliant API, it
also had the potential of failing during mutex init (but here,
because of CreateMutex failure rather than malloc failure). Since
all of misc.c's callers ignore failures, it seems like a wise idea
to avoid failures here too.
A further improvement in this area could be to unify libpq's and
ecpglib's implementations into a src/port/pthread-win32.c file.
But that doesn't seem like a bug fix, so I'll desist for now.
In preparation for the aforementioned bug fix, back-patch to all
supported branches.
Discussion: https://postgr.es/m/[email protected]
Branch
------
REL_16_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/9440d23a018cab5e78cb4aa11e8a5c558dd0bb36
Modified Files
--------------
src/interfaces/ecpg/ecpglib/misc.c | 37 +++++++++++++++++++-----
src/interfaces/ecpg/include/ecpg-pthread-win32.h | 22 +++++---------
src/interfaces/libpq/fe-connect.c | 16 ----------
src/interfaces/libpq/fe-secure-openssl.c | 20 -------------
src/interfaces/libpq/pthread-win32.c | 26 ++++++++++-------
src/port/pthread-win32.h | 11 ++++++-
6 files changed, 63 insertions(+), 69 deletions(-)
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: pgsql: Clean up Windows-specific mutex code in libpq and ecpglib.
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox