Skip to content

Commit f84d046

Browse files
authored
add support for Zend Max Exeuction Timers on FreeBSD (#13393)
1 parent 1f7cba2 commit f84d046

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Zend/Zend.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ AC_ARG_ENABLE([zend-max-execution-timers],
306306
[ZEND_MAX_EXECUTION_TIMERS=$enableval],
307307
[ZEND_MAX_EXECUTION_TIMERS=$ZEND_ZTS])
308308
309-
AS_CASE(["$host_alias"], [*linux*], [], [ZEND_MAX_EXECUTION_TIMERS='no'])
309+
AS_CASE(["$host_alias"], [*linux*|*freebsd*], [], [ZEND_MAX_EXECUTION_TIMERS='no'])
310310
311311
PHP_CHECK_FUNC(timer_create, rt)
312312
if test "$ac_cv_func_timer_create" != "yes"; then

Zend/zend_max_execution_timer.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <errno.h>
2424
#include <sys/syscall.h>
2525
#include <sys/types.h>
26+
# ifdef __FreeBSD__
27+
# include <pthread_np.h>
28+
# endif
2629

2730
#include "zend.h"
2831
#include "zend_globals.h"
@@ -33,6 +36,13 @@
3336
# define sigev_notify_thread_id _sigev_un._tid
3437
# endif
3538

39+
// FreeBSD doesn't support CLOCK_BOOTTIME
40+
# ifdef __FreeBSD__
41+
# define ZEND_MAX_EXECUTION_TIMERS_CLOCK CLOCK_MONOTONIC
42+
# else
43+
# define ZEND_MAX_EXECUTION_TIMERS_CLOCK CLOCK_BOOTTIME
44+
# endif
45+
3646
ZEND_API void zend_max_execution_timer_init(void) /* {{{ */
3747
{
3848
pid_t pid = getpid();
@@ -45,10 +55,14 @@ ZEND_API void zend_max_execution_timer_init(void) /* {{{ */
4555
sev.sigev_notify = SIGEV_THREAD_ID;
4656
sev.sigev_value.sival_ptr = &EG(max_execution_timer_timer);
4757
sev.sigev_signo = SIGRTMIN;
58+
# ifdef __FreeBSD__
59+
sev.sigev_notify_thread_id = pthread_getthreadid_np();
60+
# else
4861
sev.sigev_notify_thread_id = (pid_t) syscall(SYS_gettid);
62+
# endif
4963

5064
// Measure wall time instead of CPU time as originally planned now that it is possible https://github.com/php/php-src/pull/6504#issuecomment-1370303727
51-
if (timer_create(CLOCK_BOOTTIME, &sev, &EG(max_execution_timer_timer)) != 0) {
65+
if (timer_create(ZEND_MAX_EXECUTION_TIMERS_CLOCK, &sev, &EG(max_execution_timer_timer)) != 0) {
5266
zend_strerror_noreturn(E_ERROR, errno, "Could not create timer");
5367
}
5468

0 commit comments

Comments
 (0)