Changeset 148 for trunk/xcache.c
- Timestamp:
- 2006-09-09T02:56:44+02:00 (7 years ago)
- File:
-
- 1 edited
-
trunk/xcache.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xcache.c
r146 r148 68 68 69 69 /* {{{ globals */ 70 static char *xc_shm_scheme = NULL; 70 71 static char *xc_mmap_path = NULL; 71 72 static char *xc_coredump_dir = NULL; … … 151 152 static void xc_entry_free_real_dmz(volatile xc_entry_t *xce) /* {{{ */ 152 153 { 153 xc _mem_free(xce->cache->mem, (xc_entry_t *)xce);154 xce->cache->mem->handlers->free(xce->cache->mem, (xc_entry_t *)xce); 154 155 } 155 156 /* }}} */ … … 253 254 { 254 255 xc_entry_t *p, **pp; 255 xc_entry_t *next;256 256 int i, c; 257 257 … … 395 395 #endif 396 396 xc_mem_t *mem = cache->mem; 397 const xc_mem_handlers_t *handlers = mem->handlers; 397 398 zend_ulong interval = (cachetype == XC_TYPE_PHP) ? xc_php_gc_interval : xc_var_gc_interval; 398 399 … … 416 417 array_init(blocks); 417 418 418 add_assoc_long_ex(return_value, ZEND_STRS("size"), xc_mem_size(mem));419 add_assoc_long_ex(return_value, ZEND_STRS("avail"), xc_mem_avail(mem));419 add_assoc_long_ex(return_value, ZEND_STRS("size"), handlers->size(mem)); 420 add_assoc_long_ex(return_value, ZEND_STRS("avail"), handlers->avail(mem)); 420 421 add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection); 421 422 422 for (b = xc_mem_freeblock_first(mem); b; b = xc_mem_freeblock_next(b)) {423 for (b = handlers->freeblock_first(mem); b; b = handlers->freeblock_next(b)) { 423 424 zval *bi; 424 425 … … 426 427 array_init(bi); 427 428 428 add_assoc_long_ex(bi, ZEND_STRS("size"), xc_mem_block_size(b));429 add_assoc_long_ex(bi, ZEND_STRS("offset"), xc_mem_block_offset(mem, b));429 add_assoc_long_ex(bi, ZEND_STRS("size"), handlers->block_size(b)); 430 add_assoc_long_ex(bi, ZEND_STRS("offset"), handlers->block_offset(mem, b)); 430 431 add_next_index_zval(blocks, bi); 431 432 #ifndef NDEBUG 432 avail += xc_mem_block_size(b);433 avail += handlers->block_size(b); 433 434 #endif 434 435 } 435 436 add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks); 436 assert(avail == xc_mem_avail(mem));437 assert(avail == handlers->avail(mem)); 437 438 } 438 439 /* }}} */ … … 1025 1026 int xc_is_rw(const void *p) /* {{{ */ 1026 1027 { 1028 xc_shm_t *shm; 1027 1029 int i; 1028 1030 if (!xc_initized) { … … 1030 1032 } 1031 1033 for (i = 0; i < xc_php_hcache.size; i ++) { 1032 if (xc_shm_is_readwrite(xc_php_caches[i]->shm, p)) { 1034 shm = xc_php_caches[i]->shm; 1035 if (shm->handlers->is_readwrite(shm, p)) { 1033 1036 return 1; 1034 1037 } 1035 1038 } 1036 1039 for (i = 0; i < xc_var_hcache.size; i ++) { 1037 if (xc_shm_is_readwrite(xc_var_caches[i]->shm, p)) { 1040 shm = xc_var_caches[i]->shm; 1041 if (shm->handlers->is_readwrite(shm, p)) { 1038 1042 return 1; 1039 1043 } … … 1044 1048 int xc_is_ro(const void *p) /* {{{ */ 1045 1049 { 1050 xc_shm_t *shm; 1046 1051 int i; 1047 1052 if (!xc_initized) { … … 1049 1054 } 1050 1055 for (i = 0; i < xc_php_hcache.size; i ++) { 1051 if (xc_shm_is_readonly(xc_php_caches[i]->shm, p)) { 1056 shm = xc_php_caches[i]->shm; 1057 if (shm->handlers->is_readonly(shm, p)) { 1052 1058 return 1; 1053 1059 } 1054 1060 } 1055 1061 for (i = 0; i < xc_var_hcache.size; i ++) { 1056 if (xc_shm_is_readonly(xc_var_caches[i]->shm, p)) { 1062 shm = xc_var_caches[i]->shm; 1063 if (shm->handlers->is_readonly(shm, p)) { 1057 1064 return 1; 1058 1065 } … … 1128 1135 /* do NOT free 1129 1136 if (cache->entries) { 1130 xc_mem_free(cache->mem, cache->entries);1137 cache->mem->handlers->free(cache->mem, cache->entries); 1131 1138 } 1132 xc_mem_free(cache->mem, cache);1139 cache->mem->handlers->free(cache->mem, cache); 1133 1140 */ 1134 xc_mem_destroy(cache->mem);1141 shm->handlers->memdestroy(cache->mem); 1135 1142 shm = cache->shm; 1136 1143 } … … 1140 1147 } 1141 1148 /* }}} */ 1142 static xc_cache_t **xc_cache_init(xc_shm_t *shm, char *ptr,xc_hash_t *hcache, xc_hash_t *hentry, xc_shmsize_t shmsize) /* {{{ */1149 static xc_cache_t **xc_cache_init(xc_shm_t *shm, xc_hash_t *hcache, xc_hash_t *hentry, xc_shmsize_t shmsize) /* {{{ */ 1143 1150 { 1144 1151 xc_cache_t **caches = NULL, *cache; … … 1164 1171 1165 1172 for (i = 0; i < hcache->size; i ++) { 1166 CHECK(mem = xc_mem_init(ptr, memsize), "Failed init memory allocator"); 1167 ptr += memsize; 1168 CHECK(cache = xc_mem_calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM"); 1169 CHECK(cache->entries = xc_mem_calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 1173 CHECK(mem = shm->handlers->meminit(shm, memsize), "Failed init memory allocator"); 1174 CHECK(cache = mem->handlers->calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM"); 1175 CHECK(cache->entries = mem->handlers->calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 1170 1176 CHECK(cache->lck = xc_lock_init(NULL), "can't create lock"); 1171 1177 … … 1179 1185 caches[i] = cache; 1180 1186 } 1181 assert(ptr <= (char*)xc_shm_ptr(shm) + shmsize);1182 1187 return caches; 1183 1188 … … 1214 1219 { 1215 1220 xc_shm_t *shm; 1216 char *ptr;1217 1221 1218 1222 xc_php_caches = xc_var_caches = NULL; 1219 1223 1220 1224 if (xc_php_size || xc_var_size) { 1221 CHECK(shm = xc_shm_init(xc_ mmap_path, ALIGN(xc_php_size) + ALIGN(xc_var_size), xc_readonly_protection), "Cannot create shm");1222 if (! xc_shm_can_readonly(shm)) {1225 CHECK(shm = xc_shm_init(xc_shm_scheme, ALIGN(xc_php_size) + ALIGN(xc_var_size), xc_readonly_protection, xc_mmap_path, NULL), "Cannot create shm"); 1226 if (!shm->handlers->can_readonly(shm)) { 1223 1227 xc_readonly_protection = 0; 1224 1228 } 1225 1229 1226 ptr = (char *)xc_shm_ptr(shm);1227 1230 if (xc_php_size) { 1228 1231 origin_compile_file = zend_compile_file; 1229 1232 zend_compile_file = xc_compile_file; 1230 1233 1231 CHECK(xc_php_caches = xc_cache_init(shm, ptr, &xc_php_hcache, &xc_php_hentry, xc_php_size), "failed init opcode cache"); 1232 ptr += ALIGN(xc_php_size); 1234 CHECK(xc_php_caches = xc_cache_init(shm, &xc_php_hcache, &xc_php_hentry, xc_php_size), "failed init opcode cache"); 1233 1235 } 1234 1236 1235 1237 if (xc_var_size) { 1236 CHECK(xc_var_caches = xc_cache_init(shm, ptr,&xc_var_hcache, &xc_var_hentry, xc_var_size), "failed init variable cache");1238 CHECK(xc_var_caches = xc_cache_init(shm, &xc_var_hcache, &xc_var_hentry, xc_var_size), "failed init variable cache"); 1237 1239 } 1238 1240 } … … 2115 2117 PHP_INI_END() 2116 2118 /* }}} */ 2117 static int xc_config_ long_disp(char *name, char *default_value) /* {{{ */2119 static int xc_config_string_disp(char *name, char *default_value) /* {{{ */ 2118 2120 { 2119 2121 char *value; … … 2131 2133 } 2132 2134 /* }}} */ 2133 #define xc_config_hash_disp xc_config_long_disp 2135 #define xc_config_hash_disp xc_config_string_disp 2136 #define xc_config_long_disp xc_config_string_disp 2134 2137 /* {{{ PHP_MINFO_FUNCTION(xcache) */ 2135 2138 static PHP_MINFO_FUNCTION(xcache) … … 2139 2142 2140 2143 php_info_print_table_start(); 2141 php_info_print_table_header(2, "XCache Support", XCACHE_MODULES);2144 php_info_print_table_header(2, "XCache Support", "enabled"); 2142 2145 php_info_print_table_row(2, "Version", XCACHE_VERSION); 2143 2146 php_info_print_table_row(2, "Modules Built", XCACHE_MODULES); … … 2169 2172 php_info_print_table_start(); 2170 2173 php_info_print_table_header(2, "Directive ", "Value"); 2174 xc_config_string_disp("xcache.shm_scheme", "mmap"); 2171 2175 xc_config_long_disp("xcache.size", "0"); 2172 2176 xc_config_hash_disp("xcache.count", "1"); … … 2250 2254 } 2251 2255 /* }}} */ 2256 static int xc_config_string(char **p, char *name, char *default_value) /* {{{ */ 2257 { 2258 char *value; 2259 2260 if (cfg_get_string(name, &value) != SUCCESS) { 2261 value = default_value; 2262 } 2263 2264 *p = strdup(value); 2265 return SUCCESS; 2266 } 2267 /* }}} */ 2252 2268 /* {{{ PHP_MINIT_FUNCTION(xcache) */ 2253 2269 static PHP_MINIT_FUNCTION(xcache) … … 2278 2294 } 2279 2295 2296 xc_config_string(&xc_shm_scheme, "xcache.shm_scheme", "mmap"); 2280 2297 xc_config_long(&xc_php_size, "xcache.size", "0"); 2281 2298 xc_config_hash(&xc_php_hcache, "xcache.count", "1"); … … 2302 2319 2303 2320 xc_init_constant(module_number TSRMLS_CC); 2321 xc_shm_init_modules(); 2304 2322 2305 2323 if ((xc_php_size || xc_var_size) && xc_mmap_path && xc_mmap_path[0]) { … … 2331 2349 pefree(xc_mmap_path, 1); 2332 2350 xc_mmap_path = NULL; 2351 } 2352 if (xc_shm_scheme) { 2353 pefree(xc_shm_scheme, 1); 2354 xc_shm_scheme = NULL; 2333 2355 } 2334 2356
Note: See TracChangeset
for help on using the changeset viewer.

