php 全局宏

CG = compiler_globals

#ifdef ZTS
# define CG(v) ZEND_TSRMG(compiler_globals_id, zend_compiler_globals *, v)
#else
# define CG(v) (compiler_globals.v)

EG = executor_globals

#ifdef ZTS
# 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

ZEND_TSRMG 是否等于 thread safe resource manager global 的缩写呢?

#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
#define ZEND_TSRMG TSRMG_STATIC
#else
#define ZEND_TSRMG TSRMG

然后到了

TSRMG

#define TSRMG(id, type, element)    (TSRMG_BULK(id, type)->element)
#define TSRMG_BULK(id, type)    ((type) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(id)])
  • 然后看tsrm_get_ls_cache 的函数
TSRM_API void *tsrm_get_ls_cache(void)
{
    return tsrm_tls_get();
}
  • 继续看 tsrm_tls_get()
#if defined(PTHREADS)
/* Thread local storage */
static pthread_key_t tls_key;
# define tsrm_tls_set(what)     pthread_setspecific(tls_key, (void*)(what))
# define tsrm_tls_get()         pthread_getspecific(tls_key)

SG = sapi_globals

#ifdef ZTS
# define SG(v) ZEND_TSRMG(sapi_globals_id, sapi_globals_struct *, v)
SAPI_API extern int sapi_globals_id;
#else
# define SG(v) (sapi_globals.v)
extern SAPI_API sapi_globals_struct sapi_globals;
#endif

你可能感兴趣的:(php 全局宏)