void apc_interned_strings_init(TSRMLS_D) { int count = APCG(shm_strings_buffer) / (sizeof(Bucket) + sizeof(Bucket*) * 2); apc_interned_strings_data = (apc_interned_strings_data_t*) apc_sma_malloc(APCG(shm_strings_buffer) TSRMLS_CC); if (apc_interned_strings_data) { memset((void *)apc_interned_strings_data, 0, APCG(shm_strings_buffer)); CREATE_LOCK(APCSG(lock)); zend_hash_init(&APCSG(interned_strings), count, NULL, NULL, 1); APCSG(interned_strings).nTableMask = APCSG(interned_strings).nTableSize - 1; APCSG(interned_strings).arBuckets = (Bucket**)((char*)apc_interned_strings_data + sizeof(apc_interned_strings_data_t)); APCSG(interned_strings_start) = (char*)APCSG(interned_strings).arBuckets + APCSG(interned_strings).nTableSize * sizeof(Bucket *); APCSG(interned_strings_end) = (char*)apc_interned_strings_data + APCG(shm_strings_buffer); APCSG(interned_strings_top) = APCSG(interned_strings_start); old_interned_strings_start = CG(interned_strings_start); old_interned_strings_end = CG(interned_strings_end); old_new_interned_string = zend_new_interned_string; old_interned_strings_snapshot = zend_interned_strings_snapshot; old_interned_strings_restore = zend_interned_strings_restore; CG(interned_strings_start) = APCSG(interned_strings_start); CG(interned_strings_end) = APCSG(interned_strings_end); zend_new_interned_string = apc_dummy_new_interned_string_for_php; zend_interned_strings_snapshot = apc_dummy_interned_strings_snapshot_for_php; zend_interned_strings_restore = apc_dummy_interned_strings_restore_for_php; apc_copy_internal_strings(TSRMLS_C); } }
PRIVATE void * ListAlloc( void ) { LIST_UNIT * lu; CREATE_LOCK( LIST_MUTEX ); WAIT_FOR_LOCK( LIST_MUTEX ); if( !GLOBAL_ALLOC_TABLE ) ListGlobalAlloc(); do { if ( ( GLOBAL_ALLOC_TABLE -> avail < ALLOC_SAFETY) || ( GLOBAL_ALLOC_TABLE -> index > (ALLOC_UNITS - ALLOC_SAFETY)) ) ListGlobalPack(); lu = (LIST_UNIT *)(&GLOBAL_ALLOC_TABLE -> unit[ GLOBAL_ALLOC_TABLE -> index ]); GLOBAL_ALLOC_TABLE -> index++; } while( lu -> check != ALLOC_FREE_FLAG ); lu -> check = ALLOC_USED_FLAG; GLOBAL_ALLOC_TABLE -> timer = TIME_COUNT; GLOBAL_ALLOC_TABLE -> avail--; RELEASE_LOCK( LIST_MUTEX ); return ( &lu -> ptr_a ); }
/* {{{ apc_cache_create */ PHP_APCU_API apc_cache_t* apc_cache_create(apc_sma_t* sma, apc_serializer_t* serializer, zend_long size_hint, zend_long gc_ttl, zend_long ttl, zend_long smart, zend_bool defend) { apc_cache_t* cache; zend_long cache_size; zend_long nslots; /* calculate number of slots */ nslots = make_prime(size_hint > 0 ? size_hint : 2000); /* allocate pointer by normal means */ cache = (apc_cache_t*) apc_emalloc(sizeof(apc_cache_t)); /* calculate cache size for shm allocation */ cache_size = sizeof(apc_cache_header_t) + nslots*sizeof(apc_cache_slot_t*); /* allocate shm */ cache->shmaddr = sma->smalloc(cache_size); if(!cache->shmaddr) { apc_error("Unable to allocate shared memory for cache structures. (Perhaps your shared memory size isn't large enough?). "); return NULL; } /* zero shm */ memset(cache->shmaddr, 0, cache_size); /* set default header */ cache->header = (apc_cache_header_t*) cache->shmaddr; cache->header->nhits = 0; cache->header->nmisses = 0; cache->header->nentries = 0; cache->header->nexpunges = 0; cache->header->gc = NULL; cache->header->stime = time(NULL); cache->header->state |= APC_CACHE_ST_NONE; /* set cache options */ cache->slots = (apc_cache_slot_t**) (((char*) cache->shmaddr) + sizeof(apc_cache_header_t)); cache->sma = sma; cache->serializer = serializer; cache->nslots = nslots; cache->gc_ttl = gc_ttl; cache->ttl = ttl; cache->smart = smart; cache->defend = defend; /* header lock */ CREATE_LOCK(&cache->header->lock); /* zero slots */ memset(cache->slots, 0, sizeof(apc_cache_slot_t*)*nslots); return cache; } /* }}} */