Skip to content

Commit 081fda6

Browse files
committed
Autotools: Refactor thread safety checks
- 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 16d9bd0 commit 081fda6

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

Zend/Zend.m4

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,12 @@ ZEND_DLSYM_CHECK
166166
ZEND_CHECK_GLOBAL_REGISTER_VARIABLES
167167
ZEND_CHECK_CPUID_COUNT
168168
169-
AC_MSG_CHECKING([whether to enable thread-safety])
169+
AC_MSG_CHECKING([whether to enable thread safety])
170170
AC_MSG_RESULT([$ZEND_ZTS])
171+
AS_VAR_IF([ZEND_ZTS], [yes], [
172+
AC_DEFINE([ZTS], [1], [Define to 1 if thread safety (ZTS) is enabled.])
173+
AS_VAR_APPEND([CFLAGS], [" -DZTS"])
174+
])
171175
172176
AC_MSG_CHECKING([whether to enable Zend debugging])
173177
AC_MSG_RESULT([$ZEND_DEBUG])
@@ -195,11 +199,6 @@ AX_CHECK_COMPILE_FLAG([-fno-common], CFLAGS="-fno-common $CFLAGS", , [-Werror])
195199
196200
AS_VAR_IF([DEBUG_CFLAGS],,, [AS_VAR_APPEND([CFLAGS], [" $DEBUG_CFLAGS"])])
197201
198-
if test "$ZEND_ZTS" = "yes"; then
199-
AC_DEFINE(ZTS,1,[ ])
200-
CFLAGS="$CFLAGS -DZTS"
201-
fi
202-
203202
ZEND_CHECK_ALIGNMENT
204203
ZEND_CHECK_SIGNALS
205204
ZEND_CHECK_MAX_EXECUTION_TIMERS

configure.ac

Lines changed: 8 additions & 18 deletions
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], [],
@@ -1372,17 +1368,11 @@ if test -z "$EXTENSION_DIR"; then
13721368
else
13731369
part1=no-debug
13741370
fi
1375-
if test "$enable_zts" = "yes"; then
1376-
part2=zts
1377-
else
1378-
part2=non-zts
1379-
fi
1371+
AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [part2=zts], [part2=non-zts])
13801372
extbasedir=$part1-$part2-$extbasedir
13811373
EXTENSION_DIR=$libdir/extensions/$extbasedir
13821374
else
1383-
if test "$enable_zts" = "yes"; then
1384-
extbasedir=$extbasedir-zts
1385-
fi
1375+
AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [extbasedir=$extbasedir-zts])
13861376

13871377
if test "$PHP_DEBUG" = "1"; then
13881378
extbasedir=$extbasedir-debug

scripts/phpize.m4

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,17 @@ php_debug_is_enabled
9393
CPPFLAGS=$old_CPPFLAGS
9494
AC_MSG_RESULT([$PHP_DEBUG])
9595

96-
AC_MSG_CHECKING([if zts is enabled])
96+
AC_MSG_CHECKING([if PHP is built with thread safety (ZTS)])
9797
old_CPPFLAGS=$CPPFLAGS
9898
CPPFLAGS="-I$phpincludedir"
99-
AC_EGREP_CPP(php_zts_is_enabled,[
99+
AC_EGREP_CPP([php_zts_is_enabled], [
100100
#include <main/php_config.h>
101101
#ifdef ZTS
102102
php_zts_is_enabled
103103
#endif
104-
],[
105-
PHP_THREAD_SAFETY=yes
106-
],[
107-
PHP_THREAD_SAFETY=no
108-
])
104+
],
105+
[PHP_THREAD_SAFETY=yes],
106+
[PHP_THREAD_SAFETY=no])
109107
CPPFLAGS=$old_CPPFLAGS
110108
AC_MSG_RESULT([$PHP_THREAD_SAFETY])
111109

win32/php_win32_globals.h

Lines changed: 1 addition & 1 deletion
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)