From: Bruno Haible Date: Mon, 6 Feb 2023 17:33:37 +0000 (+0100) Subject: setlocale-null: Don't use a lock in Cygwin >= 3.4.6. X-Git-Tag: v1.0~1704 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=6ffba6a32b3bfa13589a6b3e7489ee00a7354db2;p=gnulib.git setlocale-null: Don't use a lock in Cygwin >= 3.4.6. Road paved by Corinna Vinschen . * m4/setlocale_null.m4 (gl_FUNC_SETLOCALE_NULL): Assume that setlocale (LC_ALL, NULL) is multithread-safe in Cygwin >= 3.4.6. * lib/setlocale_null.c: Update comments. * tests/test-setlocale_null-mt-all.c: Likewise. --- diff --git a/ChangeLog b/ChangeLog index 7a2c0cfa2f..ddec3a97b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2023-02-06 Bruno Haible + + setlocale-null: Don't use a lock in Cygwin >= 3.4.6. + Road paved by Corinna Vinschen . + * m4/setlocale_null.m4 (gl_FUNC_SETLOCALE_NULL): Assume that + setlocale (LC_ALL, NULL) is multithread-safe in Cygwin >= 3.4.6. + * lib/setlocale_null.c: Update comments. + * tests/test-setlocale_null-mt-all.c: Likewise. + 2023-02-05 Bruno Haible c-nullptr: Fix conflict with libstdc++ in GCC >= 11. diff --git a/lib/setlocale_null.c b/lib/setlocale_null.c index 6ac563db14..89c8a06598 100644 --- a/lib/setlocale_null.c +++ b/lib/setlocale_null.c @@ -173,7 +173,7 @@ setlocale_null_unlocked (int category, char *buf, size_t bufsize) #endif } -#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */ +#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin < 3.4.6 */ /* Use a lock, so that no two threads can invoke setlocale_null_unlocked at the same time. */ @@ -198,7 +198,7 @@ setlocale_null_with_lock (int category, char *buf, size_t bufsize) return ret; } -# elif HAVE_PTHREAD_API /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */ +# elif HAVE_PTHREAD_API /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin < 3.4.6 */ extern # if defined _WIN32 || defined __CYGWIN__ diff --git a/m4/setlocale_null.m4 b/m4/setlocale_null.m4 index dd6a5ef538..b41df499a8 100644 --- a/m4/setlocale_null.m4 +++ b/m4/setlocale_null.m4 @@ -1,4 +1,4 @@ -# setlocale_null.m4 serial 6 +# setlocale_null.m4 serial 7 dnl Copyright (C) 2019-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -13,9 +13,23 @@ AC_DEFUN([gl_FUNC_SETLOCALE_NULL], AC_CACHE_CHECK([whether setlocale (LC_ALL, NULL) is multithread-safe], [gl_cv_func_setlocale_null_all_mtsafe], [case "$host_os" in - # Guess no on musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin. - *-musl* | darwin* | freebsd* | midnightbsd* | netbsd* | openbsd* | aix* | haiku* | cygwin*) + # Guess no on musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku. + *-musl* | darwin* | freebsd* | midnightbsd* | netbsd* | openbsd* | aix* | haiku*) gl_cv_func_setlocale_null_all_mtsafe=no ;; + # Guess no on Cygwin < 3.4.6. + cygwin*) + AC_EGREP_CPP([Lucky user], + [ +#if defined __CYGWIN__ + #include + #if CYGWIN_VERSION_DLL_COMBINED >= CYGWIN_VERSION_DLL_MAKE_COMBINED (3004, 6) + Lucky user + #endif +#endif + ], + [gl_cv_func_setlocale_null_all_mtsafe=yes], + [gl_cv_func_setlocale_null_all_mtsafe=no]) + ;; # Guess yes on glibc, HP-UX, IRIX, Solaris, native Windows. *-gnu* | gnu* | hpux* | irix* | solaris* | mingw*) gl_cv_func_setlocale_null_all_mtsafe=yes ;; diff --git a/tests/test-setlocale_null-mt-all.c b/tests/test-setlocale_null-mt-all.c index 6036c260cd..7480406639 100644 --- a/tests/test-setlocale_null-mt-all.c +++ b/tests/test-setlocale_null-mt-all.c @@ -166,7 +166,7 @@ Solaris 11.0 OK Solaris 11.4 OK Solaris OpenIndiana OK Haiku crash < 1 sec -Cygwin crash < 1 sec +Cygwin < 3.4.6 crash < 1 sec mingw OK MSVC OK (assuming compiler option /MD !) */