Skip to content

Commit 6feb7cd

Browse files
committed
fix some tests
1 parent 18ffe66 commit 6feb7cd

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

Zend/zend_timer.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737

3838
ZEND_API void zend_timer_create(void) /* {{{ */
3939
{
40-
# ifdef TIMER_DEBUG
41-
fprintf(stderr, "Trying to create timer on thread %d\n", (pid_t) syscall(SYS_gettid));
42-
# endif
43-
4440
struct sigevent sev;
4541
sev.sigev_notify = SIGEV_THREAD_ID;
4642
sev.sigev_value.sival_ptr = &EG(timer);
@@ -53,8 +49,9 @@ ZEND_API void zend_timer_create(void) /* {{{ */
5349
sev.sigev_signo = SIGIO;
5450
sev.sigev_notify_thread_id = (pid_t) syscall(SYS_gettid);
5551

56-
if (timer_create(CLOCK_THREAD_CPUTIME_ID, &sev, &EG(timer)) != 0)
52+
if (timer_create(CLOCK_THREAD_CPUTIME_ID, &sev, &EG(timer)) != 0) {
5753
zend_strerror_noreturn(E_ERROR, errno, "Could not create timer");
54+
}
5855

5956
# ifdef TIMER_DEBUG
6057
fprintf(stderr, "Timer %#jx created on thread %d\n", (uintmax_t) EG(timer), sev.sigev_notify_thread_id);
@@ -68,34 +65,45 @@ ZEND_API void zend_timer_settime(zend_long seconds) /* {{{ }*/
6865
{
6966
timer_t timer = EG(timer);
7067

71-
# ifdef TIMER_DEBUG
72-
fprintf(stderr, "Trying to set timer %#jx on thread %d (%ld seconds)\n", (uintmax_t) timer, (pid_t) syscall(SYS_gettid), seconds);
73-
# endif
74-
75-
if (timer == 0) zend_error_noreturn(E_ERROR, "Timer not created");
68+
if (timer == 0) {
69+
zend_error_noreturn(E_ERROR, "Timer not created");
70+
}
7671

7772
struct itimerspec its;
7873
its.it_value.tv_sec = seconds;
7974
its.it_value.tv_nsec = its.it_interval.tv_sec = its.it_interval.tv_nsec = 0;
8075

81-
if (timer_settime(timer, 0, &its, NULL) != 0)
76+
# ifdef TIMER_DEBUG
77+
fprintf(stderr, "Setting timer %#jx on thread %d (%ld seconds)...\n", (uintmax_t) timer, (pid_t) syscall(SYS_gettid), seconds);
78+
# endif
79+
80+
if (timer_settime(timer, 0, &its, NULL) != 0) {
8281
zend_strerror_noreturn(E_ERROR, errno, "Could not set timer");
82+
}
8383
}
8484
/* }}} */
8585

8686
ZEND_API void zend_timer_delete(void) /* {{{ */
8787
{
88-
# ifdef TIMER_DEBUG
89-
fprintf(stderr, "Trying to delete timer %#jx thread %d\n", (uintmax_t) EG(timer), (pid_t) syscall(SYS_gettid));
90-
# endif
91-
9288
timer_t timer = EG(timer);
93-
if (timer == 0) zend_error_noreturn(E_ERROR, "Timer not created");
89+
if (timer == 0) {
90+
/* Don't trigger an error here because the timer may not be initialized when PHP fail early, and on threads created by PHP but not managed by it. */
91+
# ifdef TIMER_DEBUG
92+
fprintf(stderr, "Could not delete timer that has not been created on thread %d\n", (uintmax_t) timer, (pid_t) syscall(SYS_gettid));
93+
# endif
94+
95+
return;
96+
}
97+
98+
# ifdef TIMER_DEBUG
99+
fprintf(stderr, "Deleting timer %#jx on thread %d...\n", (uintmax_t) timer, (pid_t) syscall(SYS_gettid));
100+
# endif
94101

95102
int err = timer_delete(timer);
96103
EG(timer) = 0;
97-
if (err != 0)
104+
if (err != 0) {
98105
zend_strerror_noreturn(E_ERROR, errno, "Could not delete timer");
106+
}
99107
}
100108
/* }}}} */
101109

0 commit comments

Comments
 (0)