Skip to content

Allocate a fast thread-safe-resource id for opcache #19347

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

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ext/opcache/ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

#ifdef ZTS
int jit_globals_id;
size_t jit_globals_offset;
#else
zend_jit_globals jit_globals;
#endif
Expand Down Expand Up @@ -3701,7 +3702,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
Expand Down
3 changes: 2 additions & 1 deletion ext/opcache/jit/zend_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2773,7 +2775,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))
);
}
/* }}} */
Expand Down