1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Allocate a fast thread-safe-resource id for opcache

Closes GH-19347
This commit is contained in:
Arnaud Le Blanc
2025-08-01 18:30:37 +02:00
parent 5583273906
commit 3ddbad9589
5 changed files with 13 additions and 5 deletions

View File

@@ -109,6 +109,7 @@ static zend_extension opcache_extension_entry;
zend_accel_globals accel_globals;
#else
int accel_globals_id;
size_t accel_globals_offset;
#endif
/* Points to the structure shared across all PHP processes */
@@ -3162,7 +3163,7 @@ void start_accel_extension(void)
static int accel_startup(zend_extension *extension)
{
#ifdef ZTS
accel_globals_id = ts_allocate_id(&accel_globals_id, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
accel_globals_id = ts_allocate_fast_id(&accel_globals_id, &accel_globals_offset, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
#else
accel_globals_ctor(&accel_globals);
#endif

View File

@@ -300,8 +300,9 @@ extern zend_accel_shared_globals *accel_shared_globals;
#define ZCSG(element) (accel_shared_globals->element)
#ifdef ZTS
# define ZCG(v) ZEND_TSRMG(accel_globals_id, zend_accel_globals *, v)
# define ZCG(v) ZEND_TSRMG_FAST(accel_globals_offset, zend_accel_globals *, v)
extern int accel_globals_id;
extern size_t accel_globals_offset;
#else
# define ZCG(v) (accel_globals.v)
extern zend_accel_globals accel_globals;

View File

@@ -48,6 +48,7 @@
#ifdef ZTS
int jit_globals_id;
size_t jit_globals_offset;
#else
zend_jit_globals jit_globals;
#endif
@@ -3700,7 +3701,7 @@ int zend_jit_debug_config(zend_long old_val, zend_long new_val, int stage)
void zend_jit_init(void)
{
#ifdef ZTS
jit_globals_id = ts_allocate_id(&jit_globals_id, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, (ts_allocate_dtor) zend_jit_globals_dtor);
jit_globals_id = ts_allocate_fast_id(&jit_globals_id, &jit_globals_offset, sizeof(zend_jit_globals), (ts_allocate_ctor) zend_jit_globals_ctor, (ts_allocate_dtor) zend_jit_globals_dtor);
#else
zend_jit_globals_ctor(&jit_globals);
#endif

View File

@@ -145,8 +145,9 @@ typedef struct _zend_jit_globals {
} zend_jit_globals;
#ifdef ZTS
# define JIT_G(v) ZEND_TSRMG(jit_globals_id, zend_jit_globals *, v)
# define JIT_G(v) ZEND_TSRMG_FAST(jit_globals_offset, zend_jit_globals *, v)
extern int jit_globals_id;
extern size_t jit_globals_offset;
#else
# define JIT_G(v) (jit_globals.v)
extern zend_jit_globals jit_globals;

View File

@@ -51,6 +51,8 @@
#include "ext/date/php_date.h"
#include "ext/random/php_random_csprng.h"
#include "ext/random/php_random_zend_utils.h"
#include "ext/opcache/ZendAccelerator.h"
#include "ext/opcache/jit/zend_jit.h"
#include "php_variables.h"
#include "ext/standard/credits.h"
#ifdef PHP_WIN32
@@ -2803,7 +2805,9 @@ PHPAPI void php_reserve_tsrm_memory(void)
TSRM_ALIGNED_SIZE(zend_mm_globals_size()) +
TSRM_ALIGNED_SIZE(zend_gc_globals_size()) +
TSRM_ALIGNED_SIZE(sizeof(php_core_globals)) +
TSRM_ALIGNED_SIZE(sizeof(sapi_globals_struct))
TSRM_ALIGNED_SIZE(sizeof(sapi_globals_struct)) +
TSRM_ALIGNED_SIZE(sizeof(zend_accel_globals)) +
TSRM_ALIGNED_SIZE(sizeof(zend_jit_globals))
);
}
/* }}} */