Skip to content

Commit e8a5c8e

Browse files
committed
add portability checks
1 parent d936261 commit e8a5c8e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Zend/zend_max_execution_timer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
#include "zend.h"
2828
#include "zend_globals.h"
29+
#include "zend_portability.h"
2930

3031
// Musl Libc defines this macro, glibc does not
3132
// According to "man 2 timer_create" this field should always be available, but it's not: https://sourceware.org/bugzilla/show_bug.cgi?id=27417
3233
# ifndef sigev_notify_thread_id
3334
# define sigev_notify_thread_id _sigev_un._tid
3435
# endif
3536

36-
_Thread_local int is_handler_set = 0; // whether we have set up a timer in this thread
37+
ZEND_THREAD_LOCAL bool is_handler_set = false; // whether we have set up a timer in this thread
3738

3839
ZEND_API void zend_max_execution_timer_init(void) /* {{{ */
3940
{

Zend/zend_portability.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,25 @@ char *alloca();
307307
# define ZEND_NORETURN
308308
#endif
309309

310+
#if !defined(__STDC_NO_THREADS__)
311+
# if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9))
312+
/* GCC supported _Thread_local keyword since version 4.8.0 */
313+
# define ZEND_THREAD_LOCAL
314+
# else
315+
# define ZEND_THREAD_LOCAL _Thread_local
316+
# endif
317+
#else
318+
# if defined(_MSC_VER) && _MSC_VER >= 1900
319+
# define ZEND_THREAD_LOCAL __declspec(thread)
320+
# elif defined(__GNUC__) || defined(__clang__)
321+
# define ZEND_THREAD_LOCAL __thread
322+
# else
323+
/* TODO: add support for more compilers */
324+
# define ZEND_THREAD_LOCAL
325+
# error "Define thread local storage for your compiler"
326+
# endif
327+
#endif
328+
310329
#if __has_attribute(force_align_arg_pointer)
311330
# define ZEND_STACK_ALIGNED __attribute__((force_align_arg_pointer))
312331
#else

0 commit comments

Comments
 (0)