Changeset 854 for trunk/xcache.c
- Timestamp:
- 2012-03-28T10:48:20+02:00 (14 months ago)
- File:
-
- 1 edited
-
trunk/xcache.c (modified) (67 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xcache.c
r851 r854 113 113 ZEND_DLEXPORT zend_extension zend_extension_entry; 114 114 ZEND_DECLARE_MODULE_GLOBALS(xcache); 115 116 typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t; 115 117 /* }}} */ 116 118 117 119 /* any function in *_dmz is only safe be called within locked(single thread) area */ 118 120 119 static void xc_php_add_dmz(xc_ entry_data_php_t *php) /* {{{ */120 { 121 xc_entry_data_php_t **head = &( php->cache->phps[php->hvalue]);121 static void xc_php_add_dmz(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */ 122 { 123 xc_entry_data_php_t **head = &(cache->phps[php->hvalue]); 122 124 php->next = *head; 123 125 *head = php; 124 php->cache->phps_count ++;125 } 126 /* }}} */ 127 static xc_entry_data_php_t *xc_php_store_dmz(xc_ entry_data_php_t *php TSRMLS_DC) /* {{{ */126 cache->phps_count ++; 127 } 128 /* }}} */ 129 static xc_entry_data_php_t *xc_php_store_dmz(xc_cache_t *cache, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ 128 130 { 129 131 xc_entry_data_php_t *stored_php; … … 131 133 php->hits = 0; 132 134 php->refcount = 0; 133 stored_php = xc_processor_store_xc_entry_data_php_t( php TSRMLS_CC);135 stored_php = xc_processor_store_xc_entry_data_php_t(cache, php TSRMLS_CC); 134 136 if (stored_php) { 135 xc_php_add_dmz( stored_php);137 xc_php_add_dmz(cache, stored_php); 136 138 return stored_php; 137 139 } 138 140 else { 139 php->cache->ooms ++;141 cache->ooms ++; 140 142 return NULL; 141 143 } 142 144 } 143 145 /* }}} */ 144 static xc_entry_data_php_t *xc_php_find_dmz(xc_ entry_data_php_t *php TSRMLS_DC) /* {{{ */146 static xc_entry_data_php_t *xc_php_find_dmz(xc_cache_t *cache, xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ 145 147 { 146 148 xc_entry_data_php_t *p; 147 for (p = php->cache->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) {149 for (p = cache->phps[php->hvalue]; p; p = (xc_entry_data_php_t *) p->next) { 148 150 if (memcmp(&php->md5.digest, &p->md5.digest, sizeof(php->md5.digest)) == 0) { 149 151 p->hits ++; … … 154 156 } 155 157 /* }}} */ 156 static void xc_php_free_dmz(xc_ entry_data_php_t *php) /* {{{ */157 { 158 php->cache->mem->handlers->free(php->cache->mem, (xc_entry_data_php_t *)php);158 static void xc_php_free_dmz(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */ 159 { 160 cache->mem->handlers->free(cache->mem, (xc_entry_data_php_t *)php); 159 161 } 160 162 /* }}} */ … … 164 166 } 165 167 /* }}} */ 166 static void xc_php_release_dmz(xc_ entry_data_php_t *php) /* {{{ */168 static void xc_php_release_dmz(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */ 167 169 { 168 170 if (-- php->refcount == 0) { 169 xc_entry_data_php_t **pp = &( php->cache->phps[php->hvalue]);171 xc_entry_data_php_t **pp = &(cache->phps[php->hvalue]); 170 172 xc_entry_data_php_t *p; 171 173 for (p = *pp; p; pp = &(p->next), p = p->next) { … … 173 175 /* unlink */ 174 176 *pp = p->next; 175 xc_php_free_dmz( php);177 xc_php_free_dmz(cache, php); 176 178 return; 177 179 } … … 182 184 /* }}} */ 183 185 184 static inline int xc_entry_equal_dmz( const xc_entry_t *entry1, const xc_entry_t *entry2) /* {{{ */186 static inline int xc_entry_equal_dmz(xc_entry_type_t type, const xc_entry_t *entry1, const xc_entry_t *entry2) /* {{{ */ 185 187 { 186 188 /* this function isn't required but can be in dmz */ 187 188 if (entry1->type != entry2->type) { 189 return 0; 190 } 191 switch (entry1->type) { 189 switch (type) { 192 190 case XC_TYPE_PHP: 193 191 #ifdef HAVE_INODE … … 225 223 } 226 224 /* }}} */ 227 static inline int xc_entry_has_prefix_dmz(xc_entry_t *entry, zval *prefix) /* {{{ */225 static inline int xc_entry_has_prefix_dmz(xc_entry_type_t type, xc_entry_t *entry, zval *prefix) /* {{{ */ 228 226 { 229 227 /* this function isn't required but can be in dmz */ 230 228 231 switch (entry->type) {232 case XC_TYPE_PHP:233 case XC_TYPE_VAR:234 do {235 229 #ifdef IS_UNICODE 236 if (entry->name_type != prefix->type) { 237 return 0; 238 } 239 240 if (entry->name_type == IS_UNICODE) { 241 if (entry->name.ustr.len < Z_USTRLEN_P(prefix)) { 242 return 0; 243 } 244 return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefix), Z_USTRLEN_P(prefix) * sizeof(UChar)) == 0; 245 } 246 #endif 247 if (prefix->type != IS_STRING) { 248 return 0; 249 } 250 251 if (entry->name.str.len < Z_STRLEN_P(prefix)) { 252 return 0; 253 } 254 255 return memcmp(entry->name.str.val, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)) == 0; 256 257 } while(0); 258 default: 259 assert(0); 260 } 261 return 0; 262 } 263 /* }}} */ 264 static void xc_entry_add_dmz(xc_entry_t *xce) /* {{{ */ 265 { 266 xc_entry_t **head = &(xce->cache->entries[xce->hvalue]); 230 if (entry->name_type != prefix->type) { 231 return 0; 232 } 233 234 if (entry->name_type == IS_UNICODE) { 235 if (entry->name.ustr.len < Z_USTRLEN_P(prefix)) { 236 return 0; 237 } 238 return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefix), Z_USTRLEN_P(prefix) * sizeof(UChar)) == 0; 239 } 240 #endif 241 if (prefix->type != IS_STRING) { 242 return 0; 243 } 244 245 if (entry->name.str.len < Z_STRLEN_P(prefix)) { 246 return 0; 247 } 248 249 return memcmp(entry->name.str.val, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)) == 0; 250 } 251 /* }}} */ 252 static void xc_entry_add_dmz(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce) /* {{{ */ 253 { 254 xc_entry_t **head = &(cache->entries[entryslotid]); 267 255 xce->next = *head; 268 256 *head = xce; 269 xce->cache->entries_count ++;270 } 271 /* }}} */ 272 static xc_entry_t *xc_entry_store_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */257 cache->entries_count ++; 258 } 259 /* }}} */ 260 static xc_entry_t *xc_entry_store_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce TSRMLS_DC) /* {{{ */ 273 261 { 274 262 xc_entry_t *stored_xce; … … 277 265 xce->ctime = XG(request_time); 278 266 xce->atime = XG(request_time); 279 stored_xce = xce->type == XC_TYPE_PHP280 ? (xc_entry_t *) xc_processor_store_xc_entry_php_t( (xc_entry_php_t *) xce TSRMLS_CC)281 : xc_processor_store_xc_entry_t( xce TSRMLS_CC);267 stored_xce = type == XC_TYPE_PHP 268 ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache, (xc_entry_php_t *) xce TSRMLS_CC) 269 : xc_processor_store_xc_entry_t(cache, xce TSRMLS_CC); 282 270 if (stored_xce) { 283 xc_entry_add_dmz( stored_xce);271 xc_entry_add_dmz(cache, entryslotid, stored_xce); 284 272 return stored_xce; 285 273 } 286 274 else { 287 xce->cache->ooms ++;275 cache->ooms ++; 288 276 return NULL; 289 277 } 290 278 } 291 279 /* }}} */ 292 static xc_entry_php_t *xc_entry_php_store_dmz(xc_ entry_php_t *xce TSRMLS_DC) /* {{{ */293 { 294 return (xc_entry_php_t *) xc_entry_store_dmz( (xc_entry_t *) xce TSRMLS_CC);295 } 296 /* }}} */ 297 static void xc_entry_free_real_dmz( volatile xc_entry_t *xce) /* {{{ */298 { 299 if ( xce->type == XC_TYPE_PHP) {300 xc_php_release_dmz( xce->data.php);301 } 302 xce->cache->mem->handlers->free(xce->cache->mem, (xc_entry_t *)xce);303 } 304 /* }}} */ 305 static void xc_entry_free_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */306 { 307 xce->cache->entries_count --;308 if (( xce->type == XC_TYPE_PHP ? ((xc_entry_php_t *) xce)->refcount : 0) == 0) {309 xc_entry_free_real_dmz( xce);280 static xc_entry_php_t *xc_entry_php_store_dmz(xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */ 281 { 282 return (xc_entry_php_t *) xc_entry_store_dmz(XC_TYPE_PHP, cache, entryslotid, (xc_entry_t *) xce TSRMLS_CC); 283 } 284 /* }}} */ 285 static void xc_entry_free_real_dmz(xc_entry_type_t type, xc_cache_t *cache, volatile xc_entry_t *xce) /* {{{ */ 286 { 287 if (type == XC_TYPE_PHP) { 288 xc_php_release_dmz(cache, ((xc_entry_php_t *) xce)->php); 289 } 290 cache->mem->handlers->free(cache->mem, (xc_entry_t *)xce); 291 } 292 /* }}} */ 293 static void xc_entry_free_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_entry_t *xce TSRMLS_DC) /* {{{ */ 294 { 295 cache->entries_count --; 296 if ((type == XC_TYPE_PHP ? ((xc_entry_php_t *) xce)->refcount : 0) == 0) { 297 xc_entry_free_real_dmz(type, cache, xce); 310 298 } 311 299 else { 312 xce->next = xce->cache->deletes;313 xce->cache->deletes = xce;300 xce->next = cache->deletes; 301 cache->deletes = xce; 314 302 xce->dtime = XG(request_time); 315 xce->cache->deletes_count ++;303 cache->deletes_count ++; 316 304 } 317 305 return; 318 306 } 319 307 /* }}} */ 320 static void xc_entry_remove_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */321 { 322 xc_entry_t **pp = &( xce->cache->entries[xce->hvalue]);308 static void xc_entry_remove_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce TSRMLS_DC) /* {{{ */ 309 { 310 xc_entry_t **pp = &(cache->entries[entryslotid]); 323 311 xc_entry_t *p; 324 312 for (p = *pp; p; pp = &(p->next), p = p->next) { 325 if (xc_entry_equal_dmz( xce, p)) {313 if (xc_entry_equal_dmz(type, xce, p)) { 326 314 /* unlink */ 327 315 *pp = p->next; 328 xc_entry_free_dmz( xce TSRMLS_CC);316 xc_entry_free_dmz(type, cache, xce TSRMLS_CC); 329 317 return; 330 318 } … … 333 321 } 334 322 /* }}} */ 335 static xc_entry_t *xc_entry_find_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */323 static xc_entry_t *xc_entry_find_dmz(xc_entry_type_t type, xc_cache_t *cache, xc_hash_value_t entryslotid, xc_entry_t *xce TSRMLS_DC) /* {{{ */ 336 324 { 337 325 xc_entry_t *p; 338 for (p = xce->cache->entries[xce->hvalue]; p; p = p->next) {339 if (xc_entry_equal_dmz( xce, p)) {326 for (p = cache->entries[entryslotid]; p; p = p->next) { 327 if (xc_entry_equal_dmz(type, xce, p)) { 340 328 zend_bool fresh; 341 switch ( p->type) {329 switch (type) { 342 330 case XC_TYPE_PHP: 343 331 { 344 332 xc_entry_php_t *p_php = (xc_entry_php_t *) p; 345 333 xc_entry_php_t *xce_php = (xc_entry_php_t *) xce; 346 fresh = p_php->file_mtime == xce_php->file_mtime && p ->data.php->file_size == xce->data.php->file_size;334 fresh = p_php->file_mtime == xce_php->file_mtime && p_php->php->file_size == xce_php->php->file_size; 347 335 break; 348 336 } … … 362 350 } 363 351 364 xc_entry_remove_dmz( p TSRMLS_CC);352 xc_entry_remove_dmz(type, cache, entryslotid, p TSRMLS_CC); 365 353 return NULL; 366 354 } … … 369 357 } 370 358 /* }}} */ 371 static void xc_entry_hold_php_dmz(xc_ entry_php_t *xce TSRMLS_DC) /* {{{ */359 static void xc_entry_hold_php_dmz(xc_cache_t *cache, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */ 372 360 { 373 361 TRACE("hold %s", xce->entry.name.str.val); 374 362 xce->refcount ++; 375 xc_stack_push(&XG(php_holds)[ xce->entry.cache->cacheid], (void *)xce);363 xc_stack_push(&XG(php_holds)[cache->cacheid], (void *)xce); 376 364 } 377 365 /* }}} */ … … 437 425 #define XC_ENTRY_APPLY_FUNC(name) int name(xc_entry_t *entry TSRMLS_DC) 438 426 typedef XC_ENTRY_APPLY_FUNC((*cache_apply_dmz_func_t)); 439 static void xc_entry_apply_dmz(xc_ cache_t *cache, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */427 static void xc_entry_apply_dmz(xc_entry_type_t type, xc_cache_t *cache, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */ 440 428 { 441 429 xc_entry_t *p, **pp; … … 448 436 /* unlink */ 449 437 *pp = p->next; 450 xc_entry_free_dmz( p TSRMLS_CC);438 xc_entry_free_dmz(type, cache, p TSRMLS_CC); 451 439 } 452 440 else { … … 480 468 } 481 469 /* }}} */ 482 static void xc_gc_expires_one(xc_ cache_t *cache, zend_ulong gc_interval, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */470 static void xc_gc_expires_one(xc_entry_type_t type, xc_cache_t *cache, zend_ulong gc_interval, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */ 483 471 { 484 472 TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval); … … 487 475 if (XG(request_time) - cache->last_gc_expires >= gc_interval) { 488 476 cache->last_gc_expires = XG(request_time); 489 xc_entry_apply_dmz( cache, apply_func TSRMLS_CC);477 xc_entry_apply_dmz(type, cache, apply_func TSRMLS_CC); 490 478 } 491 479 } LEAVE_LOCK(cache); … … 502 490 503 491 for (i = 0, c = xc_php_hcache.size; i < c; i ++) { 504 xc_gc_expires_one( xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_dmz TSRMLS_CC);492 xc_gc_expires_one(XC_TYPE_PHP, xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_dmz TSRMLS_CC); 505 493 } 506 494 } … … 515 503 516 504 for (i = 0, c = xc_var_hcache.size; i < c; i ++) { 517 xc_gc_expires_one( xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_dmz TSRMLS_CC);505 xc_gc_expires_one(XC_TYPE_VAR, xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_dmz TSRMLS_CC); 518 506 } 519 507 } … … 535 523 *pp = p->next; 536 524 cache->deletes_count --; 537 xc_entry_free_real_dmz( p);525 xc_entry_free_real_dmz(XC_TYPE_PHP, cache, p); 538 526 } 539 527 else { … … 649 637 } 650 638 /* }}} */ 651 static void xc_fillentry_dmz( const xc_entry_t *entry, int del, zval *list TSRMLS_DC) /* {{{ */639 static void xc_fillentry_dmz(xc_entry_type_t type, const xc_entry_t *entry, xc_hash_value_t entryslotid, int del, zval *list TSRMLS_DC) /* {{{ */ 652 640 { 653 641 zval* ei; 654 642 const xc_entry_data_php_t *php; 655 const xc_entry_data_var_t *var;656 643 xc_entry_php_t *entry_php = (xc_entry_php_t *) entry; 657 644 … … 663 650 add_assoc_long_ex(ei, ZEND_STRS("ctime"), entry->ctime); 664 651 add_assoc_long_ex(ei, ZEND_STRS("atime"), entry->atime); 665 add_assoc_long_ex(ei, ZEND_STRS("hvalue"), entry ->hvalue);652 add_assoc_long_ex(ei, ZEND_STRS("hvalue"), entryslotid); 666 653 if (del) { 667 654 add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime); … … 687 674 add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1); 688 675 #endif 689 switch ( entry->type) {676 switch (type) { 690 677 case XC_TYPE_PHP: 691 php = entry ->data.php;678 php = entry_php->php; 692 679 add_assoc_long_ex(ei, ZEND_STRS("size"), entry->size + php->size); 693 680 add_assoc_long_ex(ei, ZEND_STRS("phprefcount"), php->refcount); … … 710 697 711 698 case XC_TYPE_VAR: 712 var = &entry->data.var;713 699 add_assoc_long_ex(ei, ZEND_STRS("size"), entry->size); 714 700 break; … … 721 707 } 722 708 /* }}} */ 723 static void xc_filllist_dmz(xc_ cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */709 static void xc_filllist_dmz(xc_entry_type_t type, xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */ 724 710 { 725 711 zval* list; … … 732 718 for (i = 0, c = cache->hentry->size; i < c; i ++) { 733 719 for (e = cache->entries[i]; e; e = e->next) { 734 xc_fillentry_dmz( e, 0, list TSRMLS_CC);720 xc_fillentry_dmz(type, e, i, 0, list TSRMLS_CC); 735 721 } 736 722 } … … 740 726 array_init(list); 741 727 for (e = cache->deletes; e; e = e->next) { 742 xc_fillentry_dmz( e, 1, list TSRMLS_CC);728 xc_fillentry_dmz(XC_TYPE_PHP, e, 0, 1, list TSRMLS_CC); 743 729 } 744 730 add_assoc_zval(return_value, "deleted_list", list); … … 749 735 { 750 736 zend_uint i; 751 xc_entry_data_php_t *p = xce-> entry.data.php;737 xc_entry_data_php_t *p = xce->php; 752 738 zend_op_array *old_active_op_array = CG(active_op_array); 753 739 #ifndef ZEND_ENGINE_2 … … 839 825 TRACE("holded %d", xc_stack_count(s)); 840 826 if (xc_stack_count(s)) { 841 cache = ((xc_entry_t *)xc_stack_top(s))->cache;827 cache = caches[i]; 842 828 ENTER_LOCK(cache) { 843 829 while (xc_stack_count(s)) { … … 1007 993 /* }}} */ 1008 994 1009 static int xc_entry_init_key_php(xc_entry_ php_t *xce, const char *filename TSRMLS_DC) /* {{{ */995 static int xc_entry_init_key_php(xc_entry_hash_t *entry_hash, xc_entry_php_t *xce, const char *filename TSRMLS_DC) /* {{{ */ 1010 996 { 1011 997 char opened_path_buffer[MAXPATHLEN]; 1012 int cacheid;1013 998 1014 999 if (!filename || !SG(request_info).path_translated) { … … 1077 1062 xce->file_inode = pbuf->st_ino; 1078 1063 #endif 1079 xce-> entry.data.php->file_size = pbuf->st_size;1064 xce->php->file_size = pbuf->st_size; 1080 1065 } 1081 1066 else { /* XG(inode) */ … … 1085 1070 xce->file_inode = 0; 1086 1071 #endif 1087 xce-> entry.data.php->file_size = 0;1072 xce->php->file_size = 0; 1088 1073 } 1089 1074 … … 1104 1089 xce->entry.name.str.len = strlen(filename); 1105 1090 1106 cacheid = xc_php_hcache.size > 1 ? xc_hash_fold(xc_entry_hash_php_basename(xce TSRMLS_CC), &xc_php_hcache) : 0; 1107 xce->entry.cache = xc_php_caches[cacheid]; 1108 xce->entry.hvalue = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry); 1109 xce->entry.type = XC_TYPE_PHP; 1091 entry_hash->cacheslotid = xc_php_hcache.size > 1 ? xc_hash_fold(xc_entry_hash_php_basename(xce TSRMLS_CC), &xc_php_hcache) : 0; 1092 entry_hash->entryslotid = xc_hash_fold(xc_entry_hash_php(xce TSRMLS_CC), &xc_php_hentry); 1110 1093 xce->filepath = NULL; 1111 1094 xce->dirpath = NULL; … … 1123 1106 } 1124 1107 /* }}} */ 1125 static int xc_entry_init_key_php_md5(xc_ entry_data_php_t *php, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */1108 static int xc_entry_init_key_php_md5(xc_cache_t *cache, xc_entry_data_php_t *php, xc_entry_php_t *xce TSRMLS_DC) /* {{{ */ 1126 1109 { 1127 1110 unsigned char buf[1024]; … … 1151 1134 } 1152 1135 1153 php->cache = xce->entry.cache; 1154 php->hvalue = (xc_php_hash_md5(php TSRMLS_CC) & php->cache->hphp->mask); 1136 php->hvalue = (xc_php_hash_md5(php TSRMLS_CC) & cache->hphp->mask); 1155 1137 #ifdef XCACHE_DEBUG 1156 1138 { … … 1758 1740 TRACE("restoring %s", stored_xce->entry.name.str.val); 1759 1741 xc_processor_restore_xc_entry_php_t(&xce, stored_xce TSRMLS_CC); 1760 xc_processor_restore_xc_entry_data_php_t(stored_xce, &php, xce. entry.data.php, xc_readonly_protection TSRMLS_CC);1761 xce. entry.data.php = &php;1742 xc_processor_restore_xc_entry_data_php_t(stored_xce, &php, xce.php, xc_readonly_protection TSRMLS_CC); 1743 xce.php = &php; 1762 1744 #ifdef SHOW_DPRINT 1763 1745 xc_dprint(&xce, 0 TSRMLS_CC); … … 1798 1780 } 1799 1781 /* }}} */ 1800 static zend_op_array *xc_compile_file_ex(xc_entry_ php_t *xce, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */1782 static zend_op_array *xc_compile_file_ex(xc_entry_hash_t *entry_hash, xc_entry_php_t *xce, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ 1801 1783 { 1802 1784 zend_op_array *op_array; 1803 1785 xc_entry_php_t *stored_xce; 1804 1786 xc_entry_data_php_t *stored_php; 1805 xc_cache_t *cache = xce->entry.cache;1806 1787 zend_bool gaveup = 0; 1807 1788 zend_bool catched = 0; 1808 1789 zend_bool newlycompiled; 1809 1790 xc_sandbox_t sandbox; 1791 xc_cache_t *cache = xc_php_caches[entry_hash->cacheslotid]; 1810 1792 1811 1793 /* stale clogs precheck */ … … 1818 1800 stored_php = NULL; 1819 1801 ENTER_LOCK_EX(cache) { 1820 stored_xce = (xc_entry_php_t *) xc_entry_find_dmz( (xc_entry_t *) xce TSRMLS_CC);1802 stored_xce = (xc_entry_php_t *) xc_entry_find_dmz(XC_TYPE_PHP, cache, entry_hash->entryslotid, (xc_entry_t *) xce TSRMLS_CC); 1821 1803 if (stored_xce) { 1822 1804 xc_cache_hit_dmz(cache TSRMLS_CC); 1823 1805 1824 1806 TRACE("hit %s, holding", stored_xce->name.str.val); 1825 xc_entry_hold_php_dmz( stored_xce TSRMLS_CC);1807 xc_entry_hold_php_dmz(cache, stored_xce TSRMLS_CC); 1826 1808 } 1827 1809 else { … … 1829 1811 TRACE("miss %s", xce->name.str.val); 1830 1812 1831 if (xc_entry_init_key_php_md5( xce->entry.data.php, xce TSRMLS_CC) != SUCCESS) {1813 if (xc_entry_init_key_php_md5(cache, xce->php, xce TSRMLS_CC) != SUCCESS) { 1832 1814 gaveup = 1; 1833 1815 break; 1834 1816 } 1835 1817 1836 stored_php = xc_php_find_dmz( xce->entry.data.php TSRMLS_CC);1818 stored_php = xc_php_find_dmz(cache, xce->php TSRMLS_CC); 1837 1819 1838 1820 /* miss but compiling */ … … 1874 1856 newlycompiled = 0; 1875 1857 xc_entry_init_key_php_entry(xce, h->opened_path ? h->opened_path : h->filename TSRMLS_CC); 1876 xce-> entry.data.php = stored_php;1858 xce->php = stored_php; 1877 1859 } 1878 1860 else { … … 1883 1865 1884 1866 #ifdef HAVE_XCACHE_CONSTANT 1885 xce-> entry.data.php->constinfos = NULL;1886 #endif 1887 xce-> entry.data.php->funcinfos = NULL;1888 xce-> entry.data.php->classinfos = NULL;1867 xce->php->constinfos = NULL; 1868 #endif 1869 xce->php->funcinfos = NULL; 1870 xce->php->classinfos = NULL; 1889 1871 #ifdef ZEND_ENGINE_2_1 1890 xce-> entry.data.php->autoglobals = NULL;1891 #endif 1892 1893 memset(&xce-> entry.data.php->op_array_info, 0, sizeof(xce->entry.data.php->op_array_info));1872 xce->php->autoglobals = NULL; 1873 #endif 1874 1875 memset(&xce->php->op_array_info, 0, sizeof(xce->php->op_array_info)); 1894 1876 1895 1877 zend_try { 1896 op_array = xc_compile_php(xce, xce-> entry.data.php, h, type TSRMLS_CC);1878 op_array = xc_compile_php(xce, xce->php, h, type TSRMLS_CC); 1897 1879 } zend_catch { 1898 1880 catched = 1; … … 1904 1886 1905 1887 /* not cachable */ 1906 if (!xce-> entry.data.php->op_array) {1888 if (!xce->php->op_array) { 1907 1889 cache->compiling = 0; 1908 1890 /* it's not cachable, but don't scare the users with high misses */ … … 1935 1917 /* php_store */ 1936 1918 if (newlycompiled) { 1937 stored_php = xc_php_store_dmz( xce->entry.data.php TSRMLS_CC);1919 stored_php = xc_php_store_dmz(cache, xce->php TSRMLS_CC); 1938 1920 if (!stored_php) { 1939 1921 /* error */ … … 1943 1925 /* entry_store */ 1944 1926 xc_php_addref_dmz(stored_php); 1945 stored_xce = xc_entry_php_store_dmz( xce TSRMLS_CC);1927 stored_xce = xc_entry_php_store_dmz(cache, entry_hash->entryslotid, xce TSRMLS_CC); 1946 1928 if (stored_xce) { 1947 stored_xce-> entry.data.php = stored_php;1929 stored_xce->php = stored_php; 1948 1930 } 1949 1931 else { 1950 1932 /* error */ 1951 xc_php_release_dmz( stored_php);1933 xc_php_release_dmz(cache, stored_php); 1952 1934 } 1953 1935 } LEAVE_LOCK_EX(cache); … … 1961 1943 1962 1944 if (newlycompiled) { 1963 xc_free_php(xce-> entry.data.php TSRMLS_CC);1945 xc_free_php(xce->php TSRMLS_CC); 1964 1946 } 1965 1947 … … 1992 1974 err_aftersandbox: 1993 1975 if (newlycompiled) { 1994 xc_free_php(xce-> entry.data.php TSRMLS_CC);1976 xc_free_php(xce->php TSRMLS_CC); 1995 1977 xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC); 1996 1978 } … … 2008 1990 zend_op_array *op_array; 2009 1991 xc_entry_php_t xce; 1992 xc_entry_hash_t entry_hash; 2010 1993 xc_entry_data_php_t php; 2011 1994 const char *filename; … … 2021 2004 /* {{{ entry_init_key */ 2022 2005 filename = h->opened_path ? h->opened_path : h->filename; 2023 xce. entry.data.php = &php;2024 if (xc_entry_init_key_php(& xce, filename TSRMLS_CC) != SUCCESS) {2006 xce.php = &php; 2007 if (xc_entry_init_key_php(&entry_hash, &xce, filename TSRMLS_CC) != SUCCESS) { 2025 2008 TRACE("failed to init key for %s", filename); 2026 2009 return old_compile_file(h, type TSRMLS_CC); … … 2028 2011 /* }}} */ 2029 2012 2030 op_array = xc_compile_file_ex(& xce, h, type TSRMLS_CC);2013 op_array = xc_compile_file_ex(&entry_hash, &xce, h, type TSRMLS_CC); 2031 2014 2032 2015 xc_entry_free_key_php(&xce TSRMLS_CC); … … 2596 2579 } 2597 2580 else { 2598 xc_filllist_dmz( cache, return_value TSRMLS_CC);2581 xc_filllist_dmz(type, cache, return_value TSRMLS_CC); 2599 2582 } 2600 2583 } LEAVE_LOCK(cache); … … 2603 2586 { 2604 2587 xc_entry_t *e, *next; 2605 int i, c;2588 int entryslotid, c; 2606 2589 2607 2590 if (id < 0 || id >= size) { … … 2612 2595 cache = caches[id]; 2613 2596 ENTER_LOCK(cache) { 2614 for ( i = 0, c = cache->hentry->size; i < c; i++) {2615 for (e = cache->entries[ i]; e; e = next) {2597 for (entryslotid = 0, c = cache->hentry->size; entryslotid < c; entryslotid ++) { 2598 for (e = cache->entries[entryslotid]; e; e = next) { 2616 2599 next = e->next; 2617 xc_entry_remove_dmz( e TSRMLS_CC);2600 xc_entry_remove_dmz(type, cache, entryslotid, e TSRMLS_CC); 2618 2601 } 2619 cache->entries[ i] = NULL;2602 cache->entries[entryslotid] = NULL; 2620 2603 } 2621 2604 } LEAVE_LOCK(cache); … … 2662 2645 } while (0) 2663 2646 2664 static int xc_entry_init_key_var(xc_entry_ t *xce, zval *name TSRMLS_DC) /* {{{ */2647 static int xc_entry_init_key_var(xc_entry_hash_t *entry_hash, xc_entry_var_t *xce, zval *name TSRMLS_DC) /* {{{ */ 2665 2648 { 2666 2649 xc_hash_value_t hv; 2667 int cacheid;2668 2650 2669 2651 switch (Z_TYPE_P(name)) { … … 2681 2663 } 2682 2664 #ifdef IS_UNICODE 2683 xce->name_type = name->type; 2684 #endif 2685 xce->name = name->value; 2686 2687 hv = xc_entry_hash_var(xce TSRMLS_CC); 2688 2689 cacheid = (hv & xc_var_hcache.mask); 2690 xce->cache = xc_var_caches[cacheid]; 2665 xce->entry.name_type = name->type; 2666 #endif 2667 xce->entry.name = name->value; 2668 2669 hv = xc_entry_hash_var((xc_entry_t *) xce TSRMLS_CC); 2670 2671 entry_hash->cacheslotid = (hv & xc_var_hcache.mask); 2691 2672 hv >>= xc_var_hcache.bits; 2692 xce->hvalue = (hv & xc_var_hentry.mask); 2693 2694 xce->type = XC_TYPE_VAR; 2673 entry_hash->entryslotid = (hv & xc_var_hentry.mask); 2695 2674 return SUCCESS; 2696 2675 } … … 2700 2679 PHP_FUNCTION(xcache_get) 2701 2680 { 2702 xc_entry_t xce, *stored_xce; 2681 xc_entry_hash_t entry_hash; 2682 xc_cache_t *cache; 2683 xc_entry_var_t xce, *stored_xce; 2703 2684 zval *name; 2704 2685 int found = 0; … … 2712 2693 return; 2713 2694 } 2714 xc_entry_init_key_var(&xce, name TSRMLS_CC); 2715 2716 ENTER_LOCK(xce.cache) { 2717 stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); 2695 xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC); 2696 cache = xc_var_caches[entry_hash.cacheslotid]; 2697 2698 ENTER_LOCK(cache) { 2699 stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC); 2718 2700 if (stored_xce) { 2719 if (!VAR_ENTRY_EXPIRED( stored_xce)) {2701 if (!VAR_ENTRY_EXPIRED(&stored_xce->entry)) { 2720 2702 found = 1; 2721 xc_processor_restore_zval(return_value, stored_xce-> data.var.value, stored_xce->data.var.have_references TSRMLS_CC);2703 xc_processor_restore_zval(return_value, stored_xce->value, stored_xce->have_references TSRMLS_CC); 2722 2704 /* return */ 2723 2705 break; 2724 2706 } 2725 2707 else { 2726 xc_entry_remove_dmz( stored_xce TSRMLS_CC);2708 xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC); 2727 2709 } 2728 2710 } 2729 2711 2730 2712 RETVAL_NULL(); 2731 } LEAVE_LOCK( xce.cache);2713 } LEAVE_LOCK(cache); 2732 2714 if (found) { 2733 xc_cache_hit_dmz( xce.cache TSRMLS_CC);2715 xc_cache_hit_dmz(cache TSRMLS_CC); 2734 2716 } 2735 2717 else { 2736 xce.cache->misses ++;2718 cache->misses ++; 2737 2719 } 2738 2720 } … … 2742 2724 PHP_FUNCTION(xcache_set) 2743 2725 { 2744 xc_entry_t xce, *stored_xce; 2726 xc_entry_hash_t entry_hash; 2727 xc_cache_t *cache; 2728 xc_entry_var_t xce, *stored_xce; 2745 2729 zval *name; 2746 2730 zval *value; … … 2751 2735 } 2752 2736 2753 xce. ttl = XG(var_ttl);2754 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &name, &value, &xce. ttl) == FAILURE) {2737 xce.entry.ttl = XG(var_ttl); 2738 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &name, &value, &xce.entry.ttl) == FAILURE) { 2755 2739 return; 2756 2740 } 2757 2741 2758 2742 /* max ttl */ 2759 if (xc_var_maxttl && (!xce.ttl || xce.ttl > xc_var_maxttl)) { 2760 xce.ttl = xc_var_maxttl; 2761 } 2762 2763 xc_entry_init_key_var(&xce, name TSRMLS_CC); 2764 2765 ENTER_LOCK(xce.cache) { 2766 stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); 2743 if (xc_var_maxttl && (!xce.entry.ttl || xce.entry.ttl > xc_var_maxttl)) { 2744 xce.entry.ttl = xc_var_maxttl; 2745 } 2746 2747 xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC); 2748 cache = xc_var_caches[entry_hash.cacheslotid]; 2749 2750 ENTER_LOCK(cache) { 2751 stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC); 2767 2752 if (stored_xce) { 2768 xc_entry_remove_dmz( stored_xce TSRMLS_CC);2769 } 2770 xce. data.var.value = value;2771 RETVAL_BOOL(xc_entry_store_dmz( &xce TSRMLS_CC) != NULL ? 1 : 0);2772 } LEAVE_LOCK( xce.cache);2753 xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC); 2754 } 2755 xce.value = value; 2756 RETVAL_BOOL(xc_entry_store_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC) != NULL ? 1 : 0); 2757 } LEAVE_LOCK(cache); 2773 2758 } 2774 2759 /* }}} */ … … 2777 2762 PHP_FUNCTION(xcache_isset) 2778 2763 { 2779 xc_entry_t xce, *stored_xce; 2764 xc_entry_hash_t entry_hash; 2765 xc_cache_t *cache; 2766 xc_entry_var_t xce, *stored_xce; 2780 2767 zval *name; 2781 2768 int found = 0; … … 2789 2776 return; 2790 2777 } 2791 xc_entry_init_key_var(&xce, name TSRMLS_CC); 2792 2793 ENTER_LOCK(xce.cache) { 2794 stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); 2778 xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC); 2779 cache = xc_var_caches[entry_hash.cacheslotid]; 2780 2781 ENTER_LOCK(cache) { 2782 stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC); 2795 2783 if (stored_xce) { 2796 if (!VAR_ENTRY_EXPIRED( stored_xce)) {2784 if (!VAR_ENTRY_EXPIRED(&stored_xce->entry)) { 2797 2785 found = 1; 2798 2786 RETVAL_TRUE; … … 2801 2789 } 2802 2790 else { 2803 xc_entry_remove_dmz( stored_xce TSRMLS_CC);2791 xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC); 2804 2792 } 2805 2793 } 2806 2794 2807 2795 RETVAL_FALSE; 2808 } LEAVE_LOCK( xce.cache);2796 } LEAVE_LOCK(cache); 2809 2797 if (found) { 2810 xc_cache_hit_dmz( xce.cache TSRMLS_CC);2798 xc_cache_hit_dmz(cache TSRMLS_CC); 2811 2799 } 2812 2800 else { 2813 xce.cache->misses ++;2801 cache->misses ++; 2814 2802 } 2815 2803 } … … 2819 2807 PHP_FUNCTION(xcache_unset) 2820 2808 { 2821 xc_entry_t xce, *stored_xce; 2809 xc_entry_hash_t entry_hash; 2810 xc_cache_t *cache; 2811 xc_entry_var_t xce, *stored_xce; 2822 2812 zval *name; 2823 2813 … … 2830 2820 return; 2831 2821 } 2832 xc_entry_init_key_var(&xce, name TSRMLS_CC); 2833 2834 ENTER_LOCK(xce.cache) { 2835 stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); 2822 xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC); 2823 cache = xc_var_caches[entry_hash.cacheslotid]; 2824 2825 ENTER_LOCK(cache) { 2826 stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) &xce TSRMLS_CC); 2836 2827 if (stored_xce) { 2837 xc_entry_remove_dmz( stored_xce TSRMLS_CC);2828 xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.entryslotid, (xc_entry_t *) stored_xce TSRMLS_CC); 2838 2829 RETVAL_TRUE; 2839 2830 } … … 2841 2832 RETVAL_FALSE; 2842 2833 } 2843 } LEAVE_LOCK( xce.cache);2834 } LEAVE_LOCK(cache); 2844 2835 } 2845 2836 /* }}} */ … … 2863 2854 xc_cache_t *cache = xc_var_caches[i]; 2864 2855 ENTER_LOCK(cache) { 2865 int j, jend;2866 for ( j = 0, jend = cache->hentry->size; j < jend; j++) {2856 int entryslotid, jend; 2857 for (entryslotid = 0, jend = cache->hentry->size; entryslotid < jend; entryslotid ++) { 2867 2858 xc_entry_t *entry, *next; 2868 for (entry = cache->entries[ j]; entry; entry = next) {2859 for (entry = cache->entries[entryslotid]; entry; entry = next) { 2869 2860 next = entry->next; 2870 if (xc_entry_has_prefix_dmz( entry, prefix)) {2871 xc_entry_remove_dmz( entry TSRMLS_CC);2861 if (xc_entry_has_prefix_dmz(XC_TYPE_VAR, entry, prefix)) { 2862 xc_entry_remove_dmz(XC_TYPE_VAR, cache, entryslotid, entry TSRMLS_CC); 2872 2863 } 2873 2864 } … … 2879 2870 static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ 2880 2871 { 2881 xc_entry_t xce, *stored_xce; 2872 xc_entry_hash_t entry_hash; 2873 xc_cache_t *cache; 2874 xc_entry_var_t xce, *stored_xce; 2882 2875 zval *name; 2883 2876 long count = 1; … … 2890 2883 } 2891 2884 2892 xce. ttl = XG(var_ttl);2893 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &name, &count, &xce. ttl) == FAILURE) {2885 xce.entry.ttl = XG(var_ttl); 2886 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &name, &count, &xce.entry.ttl) == FAILURE) { 2894 2887 return; 2895 2888 } 2896 2889 2897 2890 /* max ttl */ 2898 if (xc_var_maxttl && (!xce.ttl || xce.ttl > xc_var_maxttl)) { 2899 xce.ttl = xc_var_maxttl; 2900 } 2901 2902 xc_entry_init_key_var(&xce, name TSRMLS_CC); 2903 2904 ENTER_LOCK(xce.cache) { 2905 stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); 2891 if (xc_var_maxttl && (!xce.entry.ttl || xce.entry.ttl > xc_var_maxttl)) { 2892 xce.entry.ttl = xc_var_maxttl; 2893 } 2894 2895 xc_entry_init_key_var(&entry_hash, &xce, name TSRMLS_CC); 2896 cache = xc_var_caches[entry_hash.cacheslotid]; 2897 2898 ENTER_LOCK(cache) { 2899 stored_xce = (xc_entry_var_t *) xc_entry_find_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC); 2906 2900 if (stored_xce) { 2907 2901 TRACE("incdec: gotxce %s", xce.name.str.val); 2908 2902 /* timeout */ 2909 if (VAR_ENTRY_EXPIRED( stored_xce)) {2903 if (VAR_ENTRY_EXPIRED(&(stored_xce->entry))) { 2910 2904 TRACE("%s", "incdec: expired"); 2911 xc_entry_remove_dmz( stored_xce TSRMLS_CC);2905 xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC); 2912 2906 stored_xce = NULL; 2913 2907 } 2914 2908 else { 2915 2909 /* do it in place */ 2916 xc_entry_data_var_t *stored_var = &stored_xce->data.var; 2917 if (Z_TYPE_P(stored_var->value) == IS_LONG) { 2910 if (Z_TYPE_P(stored_xce->value) == IS_LONG) { 2918 2911 zval *zv; 2919 stored_xce-> ctime = XG(request_time);2920 stored_xce-> ttl = xce.ttl;2912 stored_xce->entry.ctime = XG(request_time); 2913 stored_xce->entry.ttl = xce.entry.ttl; 2921 2914 TRACE("%s", "incdec: islong"); 2922 value = Z_LVAL_P(stored_ var->value);2915 value = Z_LVAL_P(stored_xce->value); 2923 2916 value += (inc == 1 ? count : - count); 2924 2917 RETVAL_LONG(value); 2925 2918 2926 zv = (zval *) xce.cache->shm->handlers->to_readwrite(xce.cache->shm, (char *) stored_var->value);2919 zv = (zval *) cache->shm->handlers->to_readwrite(cache->shm, (char *) stored_xce->value); 2927 2920 Z_LVAL_P(zv) = value; 2928 2921 break; /* leave lock */ … … 2930 2923 else { 2931 2924 TRACE("%s", "incdec: notlong"); 2932 xc_processor_restore_zval(&oldzval, stored_xce-> data.var.value, stored_xce->data.var.have_references TSRMLS_CC);2925 xc_processor_restore_zval(&oldzval, stored_xce->value, stored_xce->have_references TSRMLS_CC); 2933 2926 convert_to_long(&oldzval); 2934 2927 value = Z_LVAL(oldzval); … … 2943 2936 value += (inc == 1 ? count : - count); 2944 2937 RETVAL_LONG(value); 2945 stored_xce-> data.var.value = return_value;2938 stored_xce->value = return_value; 2946 2939 2947 2940 if (stored_xce) { 2948 xce. atime = stored_xce->atime;2949 xce. ctime = stored_xce->ctime;2950 xce. hits = stored_xce->hits;2951 xc_entry_remove_dmz( stored_xce TSRMLS_CC);2952 } 2953 xc_entry_store_dmz( &xce TSRMLS_CC);2954 2955 } LEAVE_LOCK( xce.cache);2941 xce.entry.atime = stored_xce->entry.atime; 2942 xce.entry.ctime = stored_xce->entry.ctime; 2943 xce.entry.hits = stored_xce->entry.hits; 2944 xc_entry_remove_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) stored_xce TSRMLS_CC); 2945 } 2946 xc_entry_store_dmz(XC_TYPE_VAR, cache, entry_hash.cacheslotid, (xc_entry_t *) &xce TSRMLS_CC); 2947 2948 } LEAVE_LOCK(cache); 2956 2949 } 2957 2950 /* }}} */
Note: See TracChangeset
for help on using the changeset viewer.

