Skip to content

Revert "ext/opcache: use C11 atomics for "restart_in" (#10276)" #10339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ static void preload_shutdown(void);
static void preload_activate(void);
static void preload_restart(void);

#ifdef HAVE_STDATOMIC_H
# define INCREMENT(v) (++ZCSG(v))
# define DECREMENT(v) (--ZCSG(v))
# define LOCKVAL(v) atomic_load(&ZCSG(v))
#elif defined(ZEND_WIN32)
#ifdef ZEND_WIN32
# define INCREMENT(v) InterlockedIncrement64(&ZCSG(v))
# define DECREMENT(v) InterlockedDecrement64(&ZCSG(v))
# define LOCKVAL(v) (ZCSG(v))
Expand Down Expand Up @@ -277,7 +273,7 @@ static ZEND_INI_MH(accel_include_path_on_modify)

static inline void accel_restart_enter(void)
{
#ifdef INCREMENT
#ifdef ZEND_WIN32
INCREMENT(restart_in);
#else
struct flock restart_in_progress;
Expand All @@ -296,7 +292,7 @@ static inline void accel_restart_enter(void)

static inline void accel_restart_leave(void)
{
#ifdef DECREMENT
#ifdef ZEND_WIN32
ZCSG(restart_in_progress) = false;
DECREMENT(restart_in);
#else
Expand All @@ -317,9 +313,7 @@ static inline void accel_restart_leave(void)
static inline int accel_restart_is_active(void)
{
if (ZCSG(restart_in_progress)) {
#ifdef LOCKVAL
return LOCKVAL(restart_in) != 0;
#else
#ifndef ZEND_WIN32
struct flock restart_check;

restart_check.l_type = F_WRLCK;
Expand All @@ -337,6 +331,8 @@ static inline int accel_restart_is_active(void)
} else {
return 1;
}
#else
return LOCKVAL(restart_in) != 0;
#endif
}
return 0;
Expand All @@ -345,7 +341,7 @@ static inline int accel_restart_is_active(void)
/* Creates a read lock for SHM access */
static inline zend_result accel_activate_add(void)
{
#ifdef INCREMENT
#ifdef ZEND_WIN32
SHM_UNPROTECT();
INCREMENT(mem_usage);
SHM_PROTECT();
Expand All @@ -368,7 +364,7 @@ static inline zend_result accel_activate_add(void)
/* Releases a lock for SHM access */
static inline void accel_deactivate_sub(void)
{
#ifdef DECREMENT
#ifdef ZEND_WIN32
if (ZCG(counted)) {
SHM_UNPROTECT();
DECREMENT(mem_usage);
Expand All @@ -391,7 +387,7 @@ static inline void accel_deactivate_sub(void)

static inline void accel_unlock_all(void)
{
#ifdef DECREMENT
#ifdef ZEND_WIN32
accel_deactivate_sub();
#else
struct flock mem_usage_unlock_all;
Expand Down Expand Up @@ -832,7 +828,7 @@ static void accel_use_shm_interned_strings(void)
HANDLE_UNBLOCK_INTERRUPTIONS();
}

#ifndef LOCKVAL
#ifndef ZEND_WIN32
static inline void kill_all_lockers(struct flock *mem_usage_check)
{
int tries;
Expand Down Expand Up @@ -899,7 +895,14 @@ static inline void kill_all_lockers(struct flock *mem_usage_check)

static inline int accel_is_inactive(void)
{
#ifdef LOCKVAL
#ifdef ZEND_WIN32
/* on Windows, we don't need kill_all_lockers() because SAPIs
that work on Windows don't manage child processes (and we
can't do anything about hanging threads anyway); therefore
on Windows, we can simply manage this counter with atomics
instead of flocks (atomics are much faster but they don't
provide us with the PID of locker processes) */

if (LOCKVAL(mem_usage) == 0) {
return SUCCESS;
}
Expand Down
16 changes: 1 addition & 15 deletions ext/opcache/ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@
#include "zend_accelerator_hash.h"
#include "zend_accelerator_debug.h"

#ifdef HAVE_STDATOMIC_H
# ifdef __cplusplus
# include <atomic>
# else
# include <stdatomic.h>
# endif
#endif // HAVE_STDATOMIC_H

#ifndef PHPAPI
# ifdef ZEND_WIN32
# define PHPAPI __declspec(dllimport)
Expand Down Expand Up @@ -269,13 +261,7 @@ typedef struct _zend_accel_shared_globals {
bool restart_pending;
zend_accel_restart_reason restart_reason;
bool cache_status_before_restart;
#ifdef HAVE_STDATOMIC_H
# ifdef __cplusplus
std::atomic_llong mem_usage, restart_in;
# else
atomic_llong mem_usage, restart_in;
# endif
#elif defined(ZEND_WIN32)
#ifdef ZEND_WIN32
LONGLONG mem_usage;
LONGLONG restart_in;
#endif
Expand Down
2 changes: 0 additions & 2 deletions ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ if test "$PHP_OPCACHE" != "no"; then
dnl Always build as shared extension
ext_shared=yes

AC_CHECK_HEADERS([stdatomic.h])

if test "$PHP_HUGE_CODE_PAGES" = "yes"; then
AC_DEFINE(HAVE_HUGE_CODE_PAGES, 1, [Define to enable copying PHP CODE pages into HUGE PAGES (experimental)])
fi
Expand Down