Commit 1ea5a084c44 for php

commit 1ea5a084c4439cfe5497a527997e53c76af12364
Merge: 2f1a54e249e 29c57a4e85d
Author: Arnaud Le Blanc <arnaud.lb@gmail.com>
Date:   Fri Nov 27 12:22:17 2026 +0100

    Merge branch 'PHP-8.6'

    * PHP-8.6:
      Admit NTS requests to OPcache SHM only in RINIT (#25509)

diff --cc ext/opcache/ZendAccelerator.c
index f5756e8be9b,d9513cdf54d..d116b8debac
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@@ -363,6 -355,18 +356,18 @@@ static bool accel_lock_reader_byte(int

  	return fcntl(lock_file, cmd, &lock) != -1;
  }
+ #endif
+
+ #if defined(ZTS) && !defined(ZEND_WIN32)
+ /* fcntl() locks belong to the process, so under ZTS they cannot tell which threads
+  * use SHM (GH-8739). The threads of this process that use SHM are counted here, and
+  * the process holds the reader lock (byte 1) whenever the count is not zero, so other
+  * processes still see it. A restart needs a zero count and a write lock on byte 1.
+  * The 0 <-> 1 transitions and the restart are serialized by accel_zts_readers_mutex,
+  * other changes of the count are lock-free. */
+ static MUTEX_T accel_zts_readers_mutex = NULL;
 -static zend_atomic_int accel_zts_readers;
++static atomic_int accel_zts_readers;
+ static time_t accel_zts_next_warning;

  /* Adds (+1, only from RINIT) or releases (-1) a reference of the calling thread.
   * Does not use ZCG() as it is also called from accel_globals_dtor(). */
@@@ -376,19 -381,20 +381,19 @@@ static bool accel_zts_readers_add(int d
  			return true;
  		}
  	}
 -#endif

  	tsrm_mutex_lock(accel_zts_readers_mutex);
 -	count = zend_atomic_int_load_ex(&accel_zts_readers);
 +	count = atomic_load(&accel_zts_readers);
  	/* waits while another process restarts the cache (it holds the write lock) */
- 	if (count == 0 && !accel_zts_lock_reader_byte(F_SETLKW, F_RDLCK)) {
+ 	if (count == 0 && !accel_lock_reader_byte(F_SETLKW, F_RDLCK)) {
  		zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(+1):  %s (%d)", strerror(errno), errno);
  		tsrm_mutex_unlock(accel_zts_readers_mutex);
  		return false;
  	}
 -	while (!zend_atomic_int_compare_exchange_ex(&accel_zts_readers, &count, count + delta));
 +	while (!atomic_compare_exchange_strong(&accel_zts_readers, &count, count + delta));
  	if (count + delta == 0) {
  		/* the last reader of this process; unlock before another thread may relock */
- 		accel_zts_lock_reader_byte(F_SETLK, F_UNLCK);
+ 		accel_lock_reader_byte(F_SETLK, F_UNLCK);
  	}
  	tsrm_mutex_unlock(accel_zts_readers_mutex);
  	return true;
@@@ -1064,8 -1083,8 +1082,8 @@@ static bool accel_restart_begin(void
  	time_t now;

  	tsrm_mutex_lock(accel_zts_readers_mutex);
 -	readers = zend_atomic_int_load_ex(&accel_zts_readers);
 +	readers = atomic_load(&accel_zts_readers);
- 	if (readers == 0 && accel_zts_lock_reader_byte(F_SETLK, F_WRLCK)) {
+ 	if (readers == 0 && accel_lock_reader_byte(F_SETLK, F_WRLCK)) {
  		return true;
  	}
  	tsrm_mutex_unlock(accel_zts_readers_mutex);
@@@ -3133,12 -3152,8 +3154,12 @@@ ZEND_RINIT_FUNCTION(zend_accelerator
  					ZCSG(last_restart_time)++;
  				}
  				accel_restart_leave();
 +
 +				restarted = true;
 +				restart_reason = ZCSG(restart_reason);
 +
- #if defined(ZTS) && !defined(ZEND_WIN32)
- 				accel_zts_restart_end();
+ #ifndef ZEND_WIN32
+ 				accel_restart_end();
  #endif
  			}
  		}