Skip to content

Commit

Permalink
using pointer to the tsrm ls cache instead of a function call
Browse files Browse the repository at this point in the history
yet another approach
  • Loading branch information
weltling committed Oct 1, 2014
1 parent c161b95 commit 76081df
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 9 deletions.
15 changes: 14 additions & 1 deletion TSRM/TSRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ TSRM_API inline void *tsrm_get_ls_cache(void);
#define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
#define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_get_ls_cache()
#define TSRMG(id, type, element) (((type) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
#define TSRMGP(id, type, element) (((type) (*((void ***) tsrm_ls_cache))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)

#define TSRMG_STATIC(id, type, element) (((type) (*((void ***) _tsrm_ls_cache))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
#define TSRMLS_CACHE_EXTERN TSRM_TLS extern void *_tsrm_ls_cache
#define TSRMLS_CACHE_DEFINE TSRM_TLS void *_tsrm_ls_cache
#define TSRMLS_CACHE_UPDATE _tsrm_ls_cache = tsrm_get_ls_cache()

/* BC only */
#define TSRMLS_D
#define TSRMLS_DC
#define TSRMLS_C
Expand All @@ -185,6 +191,13 @@ TSRM_API inline void *tsrm_get_ls_cache(void);
#define TSRMLS_FETCH()
#define TSRMLS_FETCH_FROM_CTX(ctx)
#define TSRMLS_SET_CTX(ctx)

#define TSRMG_STATIC(id, type, element)
#define TSRMLS_CACHE_EXTERN
#define TSRMLS_CACHE_DEFINE
#define TSRMLS_CACHE_UPDATE

/* BC only */
#define TSRMLS_D void
#define TSRMLS_DC
#define TSRMLS_C
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ static HashTable *global_class_table = NULL;
static HashTable *global_constants_table = NULL;
static HashTable *global_auto_globals_table = NULL;
static HashTable *global_persistent_list = NULL;
ZEND_TSRMLS_CACHE_DEFINE;
#endif

ZEND_API zend_utility_values zend_uv;
Expand Down Expand Up @@ -580,6 +581,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS
zend_executor_globals *executor_globals;
extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
extern ZEND_API ts_rsrc_id language_scanner_globals_id;
ZEND_TSRMLS_CACHE_UPDATE;
#else
extern zend_ini_scanner_globals ini_scanner_globals;
extern zend_php_scanner_globals language_scanner_globals;
Expand Down
14 changes: 14 additions & 0 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
!ZEND_USER_CODE(EG(current_execute_data)->prev_execute_data->func->common.type) || \
!(EG(current_execute_data)->prev_execute_data->opline->result_type & EXT_TYPE_UNUSED))

#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
#define ZEND_TSRMG TSRMG_STATIC
#define ZEND_TSRMLS_CACHE_EXTERN TSRMLS_CACHE_EXTERN
#define ZEND_TSRMLS_CACHE_DEFINE TSRMLS_CACHE_DEFINE
#define ZEND_TSRMLS_CACHE_UPDATE TSRMLS_CACHE_UPDATE
#else
#define ZEND_TSRMG TSRMG
#define ZEND_TSRMLS_CACHE_EXTERN
#define ZEND_TSRMLS_CACHE_DEFINE
#define ZEND_TSRMLS_CACHE_UPDATE
#endif

ZEND_TSRMLS_CACHE_EXTERN;

#ifdef HAVE_NORETURN
# if defined(ZEND_WIN32)
ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...);
Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ typedef struct _zend_alloc_globals {

#ifdef ZTS
static int alloc_globals_id;
# define AG(v) TSRMG(alloc_globals_id, zend_alloc_globals *, v)
# define AG(v) ZEND_TSRMG(alloc_globals_id, zend_alloc_globals *, v)
#else
# define AG(v) (alloc_globals.v)
static zend_alloc_globals alloc_globals;
Expand Down Expand Up @@ -2285,6 +2285,7 @@ ZEND_API void shutdown_memory_manager(int silent, int full_shutdown TSRMLS_DC)

static void alloc_globals_ctor(zend_alloc_globals *alloc_globals TSRMLS_DC)
{

#if ZEND_MM_CUSTOM
char *tmp = getenv("USE_ZEND_ALLOC");

Expand All @@ -2298,6 +2299,7 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals TSRMLS_DC)
return;
}
#endif
ZEND_TSRMLS_CACHE_UPDATE;
alloc_globals->mm_heap = zend_mm_init();
}

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ typedef struct _zend_gc_globals {
BEGIN_EXTERN_C()
ZEND_API extern int gc_globals_id;
END_EXTERN_C()
#define GC_G(v) TSRMG(gc_globals_id, zend_gc_globals *, v)
#define GC_G(v) ZEND_TSRMG(gc_globals_id, zend_gc_globals *, v)
#else
#define GC_G(v) (gc_globals.v)
extern ZEND_API zend_gc_globals gc_globals;
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_globals_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BEGIN_EXTERN_C()

/* Compiler */
#ifdef ZTS
# define CG(v) TSRMG(compiler_globals_id, zend_compiler_globals *, v)
# define CG(v) ZEND_TSRMG(compiler_globals_id, zend_compiler_globals *, v)
#else
# define CG(v) (compiler_globals.v)
extern ZEND_API struct _zend_compiler_globals compiler_globals;
Expand All @@ -41,15 +41,15 @@ int zendparse(void);

/* Executor */
#ifdef ZTS
# define EG(v) TSRMG(executor_globals_id, zend_executor_globals *, v)
# define EG(v) ZEND_TSRMG(executor_globals_id, zend_executor_globals *, v)
#else
# define EG(v) (executor_globals.v)
extern ZEND_API zend_executor_globals executor_globals;
#endif

/* Language Scanner */
#ifdef ZTS
# define LANG_SCNG(v) TSRMG(language_scanner_globals_id, zend_php_scanner_globals *, v)
# define LANG_SCNG(v) ZEND_TSRMG(language_scanner_globals_id, zend_php_scanner_globals *, v)
extern ZEND_API ts_rsrc_id language_scanner_globals_id;
#else
# define LANG_SCNG(v) (language_scanner_globals.v)
Expand All @@ -59,7 +59,7 @@ extern ZEND_API zend_php_scanner_globals language_scanner_globals;

/* INI Scanner */
#ifdef ZTS
# define INI_SCNG(v) TSRMG(ini_scanner_globals_id, zend_ini_scanner_globals *, v)
# define INI_SCNG(v) ZEND_TSRMG(ini_scanner_globals_id, zend_ini_scanner_globals *, v)
extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
#else
# define INI_SCNG(v) (ini_scanner_globals.v)
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct _zend_signal_globals_t {
} zend_signal_globals_t;

#ifdef ZTS
# define SIGG(v) TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v)
# define SIGG(v) ZEND_TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v)
BEGIN_EXTERN_C()
ZEND_API extern int zend_signal_globals_id;
END_EXTERN_C()
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_virtual_cwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ typedef struct _virtual_cwd_globals {

#ifdef ZTS
extern ts_rsrc_id cwd_globals_id;
# define CWDG(v) TSRMG(cwd_globals_id, virtual_cwd_globals *, v)
# define CWDG(v) ZEND_TSRMG(cwd_globals_id, virtual_cwd_globals *, v)
#else
extern virtual_cwd_globals cwd_globals;
# define CWDG(v) (cwd_globals.v)
Expand Down
2 changes: 2 additions & 0 deletions win32/build/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
zend_float.c zend_string.c zend_generators.c zend_virtual_cwd.c zend_ast.c \
zend_inheritance.c");

ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");

if (VCVERS == 1200) {
AC_DEFINE('ZEND_DVAL_TO_LVAL_CAST_OK', 1);
}
Expand Down

0 comments on commit 76081df

Please sign in to comment.