Skip to content

Commit 07dc9c0

Browse files
committed
Release the ZTS reader reference in accel_deactivate_sub()
- As on Windows, accel_deactivate_sub() releases the thread's reference (ZCG(counted)) and accel_unlock_all() calls it instead of unlocking the whole file. - gh8739.phpt: use two CLI server workers only on Linux and FreeBSD. Elsewhere the workers have no PDEATHSIG, outlive the server and keep the test's output open, so run-tests waits forever (macOS CI).
1 parent 0e29bb9 commit 07dc9c0

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎ext/opcache/ZendAccelerator.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ static inline void accel_deactivate_sub(void)
427427
SHM_PROTECT();
428428
}
429429
#elif defined(ZTS)
430-
/* nothing to release: accel_activate_add() never succeeds under ZTS */
430+
/* releases the reference taken in RINIT (accel_activate_add() never succeeds under ZTS) */
431+
if (ZCG(counted)) {
432+
accel_zts_readers_add(-1);
433+
ZCG(counted) = false;
434+
}
431435
#else
432436
struct flock mem_usage_unlock;
433437

@@ -444,15 +448,10 @@ static inline void accel_deactivate_sub(void)
444448

445449
static inline void accel_unlock_all(void)
446450
{
447-
#ifdef ZEND_WIN32
451+
#if defined(ZEND_WIN32) || defined(ZTS)
452+
/* Under ZTS never unlock the whole file: fcntl() locks belong to the process, and the
453+
* SHM write lock (byte 0) and the restart lock (byte 2) may be held by other threads. */
448454
accel_deactivate_sub();
449-
#elif defined(ZTS)
450-
/* Release this thread's reference only. Never unlock the whole file: fcntl() locks
451-
* belong to the process, and the SHM write lock (byte 0) and the restart lock
452-
* (byte 2) may be held by other threads. */
453-
if (ZCG(counted)) {
454-
accel_zts_readers_add(-1);
455-
}
456455
#else
457456
if (lock_file == -1) {
458457
return;

‎ext/opcache/tests/gh8739.phpt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ file_put_contents("$dir/reset.php", "<?php\nvar_dump(opcache_reset());\n");
2626

2727
include __DIR__ . '/php_cli_server.inc';
2828

29-
if (PHP_OS_FAMILY !== 'Windows') {
29+
/* elsewhere the workers outlive the server without PDEATHSIG, see php_cli_server_pdeathsig.phpt */
30+
if (PHP_OS === 'Linux' || PHP_OS === 'FreeBSD') {
3031
putenv('PHP_CLI_SERVER_WORKERS=2');
3132
}
3233
$ini = '-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.file_update_protection=0';

0 commit comments

Comments
 (0)