/* delegates */ ZEND_API void _zend_ts_hash_init(TsHashTable *ht, uint32_t nSize, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC) { #ifdef ZTS ht->mx_reader = tsrm_mutex_alloc(); ht->mx_writer = tsrm_mutex_alloc(); ht->reader = 0; #endif _zend_hash_init(TS_HASH(ht), nSize, pDestructor, persistent ZEND_FILE_LINE_RELAY_CC); }
ZEND_API int _zend_ts_hash_init_ex(TsHashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent, zend_bool bApplyProtection ZEND_FILE_LINE_DC) { #ifdef ZTS ht->mx_reader = tsrm_mutex_alloc(); ht->mx_writer = tsrm_mutex_alloc(); ht->reader = 0; #endif return _zend_hash_init_ex(TS_HASH(ht), nSize, pHashFunction, pDestructor, persistent, bApplyProtection ZEND_FILE_LINE_RELAY_CC); }
void reentrancy_startup(void) { int i; for (i = 0; i < NUMBER_OF_LOCKS; i++) { reentrant_locks[i] = tsrm_mutex_alloc(); } }
static int php_http_gnutls_mutex_create(void **m) { if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) { return SUCCESS; } else { return FAILURE; } }
/* }}} */ xc_mutex_t *xc_mutex_init(xc_mutex_t *const shared_mutex, const char *pathname, unsigned char want_inter_process) /* {{{ */ { xc_mutex_t *mutex = NULL; (void) want_inter_process; /* may be unused */ #ifndef HAVE_FORK want_inter_process = 0; #endif /* if interprocessed is needed, shared_mutex is required to be a pre-allocated memory on shm * this function can always return non-shared memory if necessary despite shared memory is given */ /* when inter-process is wanted, pthread lives in shm */ #ifdef XC_MUTEX_USE_PTHREAD if (want_inter_process) { assert(shared_mutex); mutex = shared_mutex; mutex->shared = 1; } else #endif { /* all other mutex assumed live locally */ mutex = calloc(1, sizeof(*mutex)); mutex->shared = 0; #ifdef XC_MUTEX_HAVE_INTERPROCESS_SWITCH mutex->want_inter_process = want_inter_process; #endif } #ifdef XC_MUTEX_USE_PTHREAD { /* If you see mutex leak using valgrind, see xc_mutex_destroy function */ pthread_mutexattr_t psharedm; pthread_mutexattr_init(&psharedm); pthread_mutexattr_setpshared(&psharedm, xc_want_inter_process() ? PTHREAD_PROCESS_PRIVATE : PTHREAD_PROCESS_SHARED); pthread_mutex_init(&mutex->pthread_mutex, &psharedm); } #endif #ifdef XC_MUTEX_USE_TSRM mutex->tsrm_mutex = tsrm_mutex_alloc(); #endif #ifdef XC_MUTEX_USE_FCNTL if (xc_want_inter_process()) { xc_fcntl_init(&mutex->fcntl_mutex, pathname); } #endif #ifndef NDEBUG mutex->locked = 0; #endif return mutex; }
void backtrace_zts_startup(TSRMLS_D) { #ifdef DEBUG fprintf(stderr, "[%d]: backtrace_zts_startup()\n", getpid()); fflush(stderr); #endif mutex = tsrm_mutex_alloc(); zend_hash_init(&thread_ids, 128, NULL, NULL, 1); thread_end_func = (tsrm_thread_end_func_t)tsrm_set_new_thread_end_handler(backtrace_thread_end_handler); }
/* {{{ mysqlnd_qcache_init_cache */ PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_init_cache() { MYSQLND_QCACHE *cache = calloc(1, sizeof(MYSQLND_QCACHE)); #ifndef MYSQLND_SILENT php_printf("[mysqlnd_qcache_init_cache %p]\n", cache); #endif cache->references = 1; #ifdef ZTS cache->LOCK_access = tsrm_mutex_alloc(); #endif cache->ht = malloc(sizeof(HashTable)); zend_hash_init(cache->ht, 10 /* init_elements */, NULL, NULL, TRUE /*pers*/); return cache; }
THR_RW_LOCK *thr_create_rwlock(void) { THR_RW_LOCK *l = (THR_RW_LOCK *)malloc(sizeof(THR_RW_LOCK)); #ifdef TSRM_WIN32 l->lock = tsrm_mutex_alloc(); l->event = thr_create_event(); #elif defined(PTHREADS) l->lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(l->lock,NULL); l->event = thr_create_event(); #else #endif l->count = 0; l->reset = 0; return l; }
/* Startup TSRM (call once for the entire process) */ TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename) { #if defined(GNUPTH) pth_init(); #elif defined(PTHREADS) pthread_key_create( &tls_key, 0 ); #elif defined(TSRM_ST) st_init(); st_key_create(&tls_key, 0); #elif defined(TSRM_WIN32) tls_key = TlsAlloc(); #elif defined(BETHREADS) tls_key = tls_allocate(); #endif tsrm_error_file = stderr; tsrm_error_set(debug_level, debug_filename); tsrm_tls_table_size = expected_threads; tsrm_tls_table = (tsrm_tls_entry **) calloc(tsrm_tls_table_size, sizeof(tsrm_tls_entry *)); if (!tsrm_tls_table) { TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate TLS table")); return 0; } id_count=0; resource_types_table_size = expected_resources; resource_types_table = (tsrm_resource_type *) calloc(resource_types_table_size, sizeof(tsrm_resource_type)); if (!resource_types_table) { TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate resource types table")); free(tsrm_tls_table); tsrm_tls_table = NULL; return 0; } tsmm_mutex = tsrm_mutex_alloc(); tsrm_new_thread_begin_handler = tsrm_new_thread_end_handler = NULL; TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Started up TSRM, %d expected threads, %d expected resources", expected_threads, expected_resources)); return 1; }
void zend_shared_alloc_create_lock(void) { int val; #ifdef ZTS zts_lock = tsrm_mutex_alloc(); #endif sprintf(lockfile_name, "%s/%sXXXXXX", TMP_DIR, SEM_FILENAME_PREFIX); lock_file = mkstemp(lockfile_name); fchmod(lock_file, 0666); if (lock_file == -1) { zend_accel_error(ACCEL_LOG_FATAL, "Unable to create lock file: %s (%d)", strerror(errno), errno); } val = fcntl(lock_file, F_GETFD, 0); val |= FD_CLOEXEC; fcntl(lock_file, F_SETFD, val); unlink(lockfile_name); }
void php_socket_sendrecvmsg_init(INIT_FUNC_ARGS) { /* IPv6 ancillary data */ #if defined(IPV6_RECVPKTINFO) && HAVE_IPV6 REGISTER_LONG_CONSTANT("IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IPV6_PKTINFO", IPV6_PKTINFO, CONST_CS | CONST_PERSISTENT); #endif #if defined(IPV6_RECVHOPLIMIT) && HAVE_IPV6 REGISTER_LONG_CONSTANT("IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IPV6_HOPLIMIT", IPV6_HOPLIMIT, CONST_CS | CONST_PERSISTENT); #endif /* would require some effort: REGISTER_LONG_CONSTANT("IPV6_RECVRTHDR", IPV6_RECVRTHDR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, CONST_CS | CONST_PERSISTENT); */ #if defined(IPV6_RECVTCLASS) && HAVE_IPV6 REGISTER_LONG_CONSTANT("IPV6_RECVTCLASS", IPV6_RECVTCLASS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IPV6_TCLASS", IPV6_TCLASS, CONST_CS | CONST_PERSISTENT); #endif /* REGISTER_LONG_CONSTANT("IPV6_RTHDR", IPV6_RTHDR, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IPV6_HOPOPTS", IPV6_HOPOPTS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IPV6_DSTOPTS", IPV6_DSTOPTS, CONST_CS | CONST_PERSISTENT); */ #ifdef SCM_RIGHTS REGISTER_LONG_CONSTANT("SCM_RIGHTS", SCM_RIGHTS, CONST_CS | CONST_PERSISTENT); #endif #ifdef SO_PASSCRED REGISTER_LONG_CONSTANT("SCM_CREDENTIALS", SCM_CREDENTIALS, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_PASSCRED", SO_PASSCRED, CONST_CS | CONST_PERSISTENT); #endif #ifdef ZTS ancillary_mutex = tsrm_mutex_alloc(); #endif }
void php_win32_init_rng_lock() { php_lock_win32_cryptoctx = tsrm_mutex_alloc(); }
void php_init_crypt_r() { #ifdef ZTS php_crypt_extended_init_lock = tsrm_mutex_alloc(); #endif }
/* on merge: added function */ void mkd_tags_on_startup(INIT_FUNC_ARGS) { #ifdef ZTS tags_mutex = tsrm_mutex_alloc(); #endif }