Skip to content

Commit 62f75a7

Browse files
authored
Autotools: Refactor thread safety checks (php#15214)
- The ZTS is defined on only one place - Added help text for ZTS preprocessor macro - The 'enable_zts' variable replaced with PHP_THREAD_SAFETY in configure.ac. - Nits fixed.
1 parent bb299a0 commit 62f75a7

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

Zend/Zend.m4

+5-6
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,12 @@ ZEND_DLSYM_CHECK
163163
ZEND_CHECK_GLOBAL_REGISTER_VARIABLES
164164
ZEND_CHECK_CPUID_COUNT
165165
166-
AC_MSG_CHECKING([whether to enable thread-safety])
166+
AC_MSG_CHECKING([whether to enable thread safety])
167167
AC_MSG_RESULT([$ZEND_ZTS])
168+
AS_VAR_IF([ZEND_ZTS], [yes], [
169+
AC_DEFINE([ZTS], [1], [Define to 1 if thread safety (ZTS) is enabled.])
170+
AS_VAR_APPEND([CFLAGS], [" -DZTS"])
171+
])
168172
169173
AC_MSG_CHECKING([whether to enable Zend debugging])
170174
AC_MSG_RESULT([$ZEND_DEBUG])
@@ -191,11 +195,6 @@ AX_CHECK_COMPILE_FLAG([-fno-common], CFLAGS="-fno-common $CFLAGS", , [-Werror])
191195
192196
AS_VAR_IF([DEBUG_CFLAGS],,, [AS_VAR_APPEND([CFLAGS], [" $DEBUG_CFLAGS"])])
193197
194-
if test "$ZEND_ZTS" = "yes"; then
195-
AC_DEFINE(ZTS,1,[ ])
196-
CFLAGS="$CFLAGS -DZTS"
197-
fi
198-
199198
ZEND_CHECK_ALIGNMENT
200199
ZEND_CHECK_SIGNALS
201200
ZEND_CHECK_MAX_EXECUTION_TIMERS

configure.ac

+8-18
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,10 @@ if test -z "$PHP_INSTALLED_SAPIS"; then
295295
AC_MSG_ERROR([Nothing to build.])
296296
fi
297297

298-
dnl Force ZTS.
299-
if test "$enable_zts" = "yes"; then
300-
dnl Add pthreads linker and compiler flags.
298+
dnl Add POSIX threads compilation and linker flags when thread safety is enabled
299+
dnl with either the '--enable-zts' configure option or automatically enabled by
300+
dnl PHP SAPIs. For example, Apache SAPI.
301+
AS_VAR_IF([enable_zts], [yes], [
301302
if test -n "$ac_cv_pthreads_lib"; then
302303
LIBS="$LIBS -l$ac_cv_pthreads_lib"
303304
fi
@@ -306,7 +307,7 @@ if test "$enable_zts" = "yes"; then
306307
fi
307308
308309
PTHREADS_FLAGS
309-
fi
310+
])
310311

311312
dnl Starting system checks.
312313
dnl ----------------------------------------------------------------------------
@@ -847,12 +848,7 @@ AC_ARG_ENABLE([zts],
847848
[ZEND_ZTS=$enableval],
848849
[ZEND_ZTS=no])
849850

850-
if test "$ZEND_ZTS" = "yes"; then
851-
AC_DEFINE(ZTS, 1,[ ])
852-
PHP_THREAD_SAFETY=yes
853-
else
854-
PHP_THREAD_SAFETY=no
855-
fi
851+
AS_VAR_IF([ZEND_ZTS], [yes], [PHP_THREAD_SAFETY=yes], [PHP_THREAD_SAFETY=no])
856852

857853
AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [
858854
AS_VAR_IF([pthreads_working], [yes], [],
@@ -1368,17 +1364,11 @@ if test -z "$EXTENSION_DIR"; then
13681364
extbasedir=$ZEND_MODULE_API_NO
13691365
if test "$oldstyleextdir" = "yes"; then
13701366
AS_VAR_IF([PHP_DEBUG], [1], [part1=debug], [part1=no-debug])
1371-
if test "$enable_zts" = "yes"; then
1372-
part2=zts
1373-
else
1374-
part2=non-zts
1375-
fi
1367+
AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [part2=zts], [part2=non-zts])
13761368
extbasedir=$part1-$part2-$extbasedir
13771369
EXTENSION_DIR=$libdir/extensions/$extbasedir
13781370
else
1379-
if test "$enable_zts" = "yes"; then
1380-
extbasedir=$extbasedir-zts
1381-
fi
1371+
AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [extbasedir=$extbasedir-zts])
13821372
AS_VAR_IF([PHP_DEBUG], [1], [extbasedir=$extbasedir-debug])
13831373
EXTENSION_DIR=$libdir/$extbasedir
13841374
fi

scripts/phpize.m4

+5-7
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,17 @@ php_debug_is_enabled
9191
CPPFLAGS=$old_CPPFLAGS
9292
AC_MSG_RESULT([$PHP_DEBUG])
9393

94-
AC_MSG_CHECKING([if zts is enabled])
94+
AC_MSG_CHECKING([if PHP is built with thread safety (ZTS)])
9595
old_CPPFLAGS=$CPPFLAGS
9696
CPPFLAGS="-I$phpincludedir"
97-
AC_EGREP_CPP(php_zts_is_enabled,[
97+
AC_EGREP_CPP([php_zts_is_enabled], [
9898
#include <main/php_config.h>
9999
#ifdef ZTS
100100
php_zts_is_enabled
101101
#endif
102-
],[
103-
PHP_THREAD_SAFETY=yes
104-
],[
105-
PHP_THREAD_SAFETY=no
106-
])
102+
],
103+
[PHP_THREAD_SAFETY=yes],
104+
[PHP_THREAD_SAFETY=no])
107105
CPPFLAGS=$old_CPPFLAGS
108106
AC_MSG_RESULT([$PHP_THREAD_SAFETY])
109107

win32/php_win32_globals.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef PHP_WIN32_GLOBALS_H
1818
#define PHP_WIN32_GLOBALS_H
1919

20-
/* misc globals for thread-safety under win32 */
20+
/* misc globals for thread safety under win32 */
2121

2222
#include "win32/sendmail.h"
2323

0 commit comments

Comments
 (0)