- Timestamp:
- 2006-09-09T02:56:44+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
- 1 moved
-
Makefile.frag (modified) (1 diff)
-
config.m4 (modified) (1 diff)
-
config.w32 (modified) (1 diff)
-
mem.c (modified) (14 diffs)
-
mem.h (modified) (1 diff)
-
mmap.c (modified) (9 diffs)
-
processor/head.m4 (modified) (1 diff)
-
processor/main.m4 (modified) (1 diff)
-
utils.c (modified) (1 diff)
-
xc_malloc.c (added)
-
xc_shm.c (added)
-
xc_shm.h (moved) (moved from trunk/myshm.h) (1 diff)
-
xcache.c (modified) (23 diffs)
-
xcache.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile.frag
r75 r148 32 32 disassembler.lo: $(XCACHE_PROC_H) $(srcdir)/processor.c 33 33 34 $(builddir)/xcache.lo: $(XCACHE_PROC_H) $(srcdir)/ myshm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h35 xcache.lo: $(XCACHE_PROC_H) $(srcdir)/ myshm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h34 $(builddir)/xcache.lo: $(XCACHE_PROC_H) $(srcdir)/xc_shm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h 35 xcache.lo: $(XCACHE_PROC_H) $(srcdir)/xc_shm.h $(srcdir)/stack.h $(srcdir)/xcache_globals.h $(srcdir)/xcache.c $(srcdir)/foreachcoresig.h 36 36 37 37 xcachesvnclean: clean -
trunk/config.m4
r95 r148 28 28 mmap.c \ 29 29 mem.c \ 30 xc_malloc.c \ 31 xc_shm.c \ 30 32 const_string.c \ 31 33 opcode_spec.c \ -
trunk/config.w32
r95 r148 16 16 mmap.c \ 17 17 mem.c \ 18 xc_malloc.c \ 19 xc_shm.c \ 18 20 const_string.c \ 19 21 opcode_spec.c \ -
trunk/mem.c
r112 r148 9 9 #include <stdlib.h> 10 10 #include <string.h> 11 #include "mem.h" 11 #define XC_SHM_IMPL 12 #define XC_MEM_IMPL 13 #include "xc_shm.h" 12 14 #include "align.h" 13 15 … … 37 39 38 40 struct _xc_mem_t { 41 const xc_mem_handlers_t *handlers; 42 xc_shm_t *shm; 39 43 xc_memsize_t size; 40 44 xc_memsize_t avail; /* total free */ … … 75 79 76 80 77 void *xc_mem_malloc(xc_mem_t *mem, xc_memsize_t size) /* {{{ */81 static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */ 78 82 { 79 83 xc_block_t *prev, *cur; … … 183 187 } 184 188 /* }}} */ 185 int xc_mem_free(xc_mem_t *mem, const void *p) /* {{{ return block size freed */189 static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */ 186 190 { 187 191 xc_block_t *cur, *b; … … 237 241 } 238 242 /* }}} */ 239 void *xc_mem_calloc(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size) /* {{{ */243 static XC_MEM_CALLOC(xc_mem_calloc) /* {{{ */ 240 244 { 241 245 xc_memsize_t realsize = memb * size; … … 248 252 } 249 253 /* }}} */ 250 void *xc_mem_realloc(xc_mem_t *mem, const void *p, xc_memsize_t size) /* {{{ */254 static XC_MEM_REALLOC(xc_mem_realloc) /* {{{ */ 251 255 { 252 256 void *newp = xc_mem_malloc(mem, size); … … 258 262 } 259 263 /* }}} */ 260 char *xc_mem_strndup(xc_mem_t *mem, const char *str, xc_memsize_t len) /* {{{ */264 static XC_MEM_STRNDUP(xc_mem_strndup) /* {{{ */ 261 265 { 262 266 void *p = xc_mem_malloc(mem, len + 1); … … 267 271 } 268 272 /* }}} */ 269 char *xc_mem_strdup(xc_mem_t *mem, const char *str) /* {{{ */273 static XC_MEM_STRDUP(xc_mem_strdup) /* {{{ */ 270 274 { 271 275 return xc_mem_strndup(mem, str, strlen(str)); … … 273 277 /* }}} */ 274 278 275 xc_memsize_t xc_mem_avail(xc_mem_t *mem) /* {{{ */279 static XC_MEM_AVAIL(xc_mem_avail) /* {{{ */ 276 280 { 277 281 return mem->avail; 278 282 } 279 283 /* }}} */ 280 xc_memsize_t xc_mem_size(xc_mem_t *mem) /* {{{ */284 static XC_MEM_SIZE(xc_mem_size) /* {{{ */ 281 285 { 282 286 return mem->size; … … 284 288 /* }}} */ 285 289 286 const xc_block_t *xc_mem_freeblock_first(xc_mem_t *mem) /* {{{ */290 static XC_MEM_FREEBLOCK_FIRST(xc_mem_freeblock_first) /* {{{ */ 287 291 { 288 292 return mem->headblock->next; 289 293 } 290 294 /* }}} */ 291 const xc_block_t *xc_mem_freeblock_next(const xc_block_t *block) /* {{{ */295 XC_MEM_FREEBLOCK_NEXT(xc_mem_freeblock_next) /* {{{ */ 292 296 { 293 297 return block->next; 294 298 } 295 299 /* }}} */ 296 xc_memsize_t xc_mem_block_size(const xc_block_t *block) /* {{{ */300 XC_MEM_BLOCK_SIZE(xc_mem_block_size) /* {{{ */ 297 301 { 298 302 return block->size; 299 303 } 300 304 /* }}} */ 301 xc_memsize_t xc_mem_block_offset(const xc_mem_t *mem, const xc_block_t *block) /* {{{ */305 XC_MEM_BLOCK_OFFSET(xc_mem_block_offset) /* {{{ */ 302 306 { 303 307 return ((char *) block) - ((char *) mem); … … 305 309 /* }}} */ 306 310 307 xc_mem_t *xc_mem_init(void *ptr, xc_memsize_t size) /* {{{ */ 308 { 309 xc_mem_t *mem; 311 static XC_MEM_INIT(xc_mem_init) /* {{{ */ 312 { 310 313 xc_block_t *b; 311 312 314 #define MINSIZE (ALIGN(sizeof(xc_mem_t)) + sizeof(xc_block_t)) 313 315 /* requires at least the header and 1 tail block */ … … 316 318 return NULL; 317 319 } 318 mem = (xc_mem_t *) ptr;320 mem->shm = shm; 319 321 mem->size = size; 320 322 mem->avail = size - MINSIZE; … … 332 334 } 333 335 /* }}} */ 334 void xc_mem_destroy(xc_mem_t *mem) /* {{{ */336 static XC_MEM_DESTROY(xc_mem_destroy) /* {{{ */ 335 337 { 336 338 } … … 381 383 /* }}} */ 382 384 #endif 385 386 typedef struct { 387 const char *name; 388 const xc_mem_handlers_t *handlers; 389 } xc_mem_scheme_t; 390 static xc_mem_scheme_t xc_mem_schemes[10]; 391 392 int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers) /* {{{ */ 393 { 394 int i; 395 for (i = 0; i < 10; i ++) { 396 if (!xc_mem_schemes[i].name) { 397 xc_mem_schemes[i].name = name; 398 xc_mem_schemes[i].handlers = handlers; 399 return 1; 400 } 401 } 402 return 0; 403 } 404 /* }}} */ 405 const xc_mem_handlers_t *xc_mem_scheme_find(const char *name) /* {{{ */ 406 { 407 int i; 408 for (i = 0; i < 10 && xc_mem_schemes[i].name; i ++) { 409 if (strcmp(xc_mem_schemes[i].name, name) == 0) { 410 return xc_mem_schemes[i].handlers; 411 } 412 } 413 return NULL; 414 } 415 /* }}} */ 416 417 static xc_mem_handlers_t xc_mem_mem_handlers = XC_MEM_HANDLERS(mem); 418 void xc_shm_mem_init() /* {{{ */ 419 { 420 memset(xc_mem_schemes, 0, sizeof(xc_mem_schemes)); 421 422 if (xc_mem_scheme_register("mem", &xc_mem_mem_handlers) == 0) { 423 zend_error(E_ERROR, "XCache: failed to register mem mem_scheme"); 424 } 425 } 426 /* }}} */ -
trunk/mem.h
r1 r148 3 3 typedef unsigned int xc_memsize_t; 4 4 5 void *xc_mem_malloc(xc_mem_t *mem, xc_memsize_t size); 6 int xc_mem_free(xc_mem_t *mem, const void *p); 7 void *xc_mem_calloc(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size); 8 void *xc_mem_realloc(xc_mem_t *mem, const void *p, xc_memsize_t size); 9 char *xc_mem_strndup(xc_mem_t *mem, const char *str, xc_memsize_t len); 10 char *xc_mem_strdup(xc_mem_t *mem, const char *str); 11 const xc_block_t *xc_mem_freeblock_first(xc_mem_t *mem); 12 const xc_block_t *xc_mem_freeblock_next(const xc_block_t *block); 13 xc_memsize_t xc_mem_block_size(const xc_block_t *block); 14 xc_memsize_t xc_mem_block_offset(const xc_mem_t *mem, const xc_block_t *block); 5 /* shm::mem */ 6 #define XC_MEM_MALLOC(func) void *func(xc_mem_t *mem, xc_memsize_t size) 7 #define XC_MEM_FREE(func) xc_memsize_t func(xc_mem_t *mem, const void *p) 8 #define XC_MEM_CALLOC(func) void *func(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size) 9 #define XC_MEM_REALLOC(func) void *func(xc_mem_t *mem, const void *p, xc_memsize_t size) 10 #define XC_MEM_STRNDUP(func) char *func(xc_mem_t *mem, const char *str, xc_memsize_t len) 11 #define XC_MEM_STRDUP(func) char *func(xc_mem_t *mem, const char *str) 12 #define XC_MEM_AVAIL(func) xc_memsize_t func(xc_mem_t *mem) 13 #define XC_MEM_SIZE(func) xc_memsize_t func(xc_mem_t *mem) 14 #define XC_MEM_FREEBLOCK_FIRST(func) const xc_block_t *func(xc_mem_t *mem) 15 #define XC_MEM_FREEBLOCK_NEXT(func) const xc_block_t *func(const xc_block_t *block) 16 #define XC_MEM_BLOCK_SIZE(func) xc_memsize_t func(const xc_block_t *block) 17 #define XC_MEM_BLOCK_OFFSET(func) xc_memsize_t func(const xc_mem_t *mem, const xc_block_t *block) 15 18 16 xc_memsize_t xc_mem_avail(xc_mem_t *mem); 17 xc_memsize_t xc_mem_size(xc_mem_t *mem); 19 #define XC_MEM_INIT(func) xc_mem_t *func(xc_shm_t *shm, xc_mem_t *mem, xc_memsize_t size) 20 #define XC_MEM_DESTROY(func) void func(xc_mem_t *mem) 18 21 19 xc_mem_t *xc_mem_init(void *ptr, xc_memsize_t size); 20 void xc_mem_destroy(xc_mem_t *mem); 22 #define XC_MEM_HANDLERS(name) { \ 23 xc_##name##_malloc \ 24 , xc_##name##_free \ 25 , xc_##name##_calloc \ 26 , xc_##name##_realloc \ 27 , xc_##name##_strndup \ 28 , xc_##name##_strdup \ 29 , xc_##name##_avail \ 30 , xc_##name##_size \ 31 , xc_##name##_freeblock_first \ 32 , xc_##name##_freeblock_next \ 33 , xc_##name##_block_size \ 34 , xc_##name##_block_offset \ 35 \ 36 , xc_##name##_init \ 37 , xc_##name##_destroy \ 38 } 39 40 typedef struct { 41 XC_MEM_MALLOC((*malloc)); 42 XC_MEM_FREE((*free)); 43 XC_MEM_CALLOC((*calloc)); 44 XC_MEM_REALLOC((*realloc)); 45 XC_MEM_STRNDUP((*strndup)); 46 XC_MEM_STRDUP((*strdup)); 47 XC_MEM_AVAIL((*avail)); 48 XC_MEM_SIZE((*size)); 49 XC_MEM_FREEBLOCK_FIRST((*freeblock_first)); 50 XC_MEM_FREEBLOCK_NEXT((*freeblock_next)); 51 XC_MEM_BLOCK_SIZE((*block_size)); 52 XC_MEM_BLOCK_OFFSET((*block_offset)); 53 54 XC_MEM_INIT((*init)); 55 XC_MEM_DESTROY((*destroy)); 56 } xc_mem_handlers_t; 57 58 #ifndef XC_MEM_IMPL 59 struct _xc_mem_t { 60 const xc_mem_handlers_t *handlers; 61 xc_shm_t *shm; 62 }; 63 #endif 64 65 int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers); 66 const xc_mem_handlers_t *xc_mem_scheme_find(const char *name); -
trunk/mmap.c
r119 r148 32 32 33 33 #include "php.h" 34 #include "myshm.h" 34 #define XC_SHM_IMPL 35 #include "xc_shm.h" 35 36 36 37 #ifndef max … … 40 41 // {{{ xc_shm_t 41 42 struct _xc_shm_t { 43 xc_shm_handlers_t *handlers; 42 44 void *ptr; 43 45 void *ptr_ro; … … 46 48 char *name; 47 49 int newfile; 50 xc_shmsize_t memoffset; 48 51 #ifdef ZEND_WIN32 49 52 HANDLE hmap; … … 64 67 #define PTR_SUB(ptr, v) (((char *) (ptr)) - (v)) 65 68 66 int xc_shm_can_readonly(xc_shm_t *shm) /* {{{ */69 static XC_SHM_CAN_READONLY(xc_mmap_can_readonly) /* {{{ */ 67 70 { 68 71 return shm->ptr_ro != NULL; 69 72 } 70 73 /* }}} */ 71 int xc_shm_is_readwrite(xc_shm_t *shm, const void *p) /* {{{ */74 static XC_SHM_IS_READWRITE(xc_mmap_is_readwrite) /* {{{ */ 72 75 { 73 76 return p >= shm->ptr && (char *)p < (char *)shm->ptr + shm->size; 74 77 } 75 78 /* }}} */ 76 int xc_shm_is_readonly(xc_shm_t *shm, const void *p) /* {{{ */77 { 78 return xc_ shm_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size;79 } 80 /* }}} */ 81 void *xc_shm_to_readwrite(xc_shm_t *shm, void *p) /* {{{ */79 static XC_SHM_IS_READONLY(xc_mmap_is_readonly) /* {{{ */ 80 { 81 return xc_mmap_can_readonly(shm) && p >= shm->ptr_ro && (char *)p < (char *)shm->ptr_ro + shm->size; 82 } 83 /* }}} */ 84 static XC_SHM_TO_READWRITE(xc_mmap_to_readwrite) /* {{{ */ 82 85 { 83 86 if (shm->diff) { 84 assert(xc_ shm_is_readonly(p));87 assert(xc_mmap_is_readonly(p)); 85 88 p = PTR_SUB(p, shm->diff); 86 89 } 87 assert(xc_ shm_is_readwrite(p));90 assert(xc_mmap_is_readwrite(p)); 88 91 return p; 89 92 } 90 93 /* }}} */ 91 void *xc_shm_to_readonly(xc_shm_t *shm, void *p) /* {{{ */94 static XC_SHM_TO_READONLY(xc_mmap_to_readonly) /* {{{ */ 92 95 { 93 96 assert(xc_shm_is_readwrite(p)); 94 97 if (shm->diff) { 95 98 p = PTR_ADD(p, shm->diff); 96 assert(xc_ shm_is_readonly(p));99 assert(xc_mmap_is_readonly(p)); 97 100 } 98 101 return p; … … 100 103 /* }}} */ 101 104 102 void xc_shm_destroy(xc_shm_t *shm) /* {{{ */105 static XC_SHM_DESTROY(xc_mmap_destroy) /* {{{ */ 103 106 { 104 107 if (shm->ptr_ro) { … … 141 144 } 142 145 /* }}} */ 143 xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_protection) /* {{{ */146 static XC_SHM_INIT(xc_mmap_init) /* {{{ */ 144 147 { 145 148 #ifdef ZEND_WIN32 … … 154 157 char tmpname[sizeof(TMP_PATH) - 1 + 100]; 155 158 const char *errstr = NULL; 159 const char *path = (const char *) arg1; 156 160 157 161 CHECK(shm = calloc(1, sizeof(xc_shm_t)), "shm OOM"); … … 273 277 } 274 278 if (shm) { 275 xc_ shm_destroy(shm);279 xc_mmap_destroy(shm); 276 280 } 277 281 if (errstr) { … … 283 287 /* }}} */ 284 288 285 void *xc_shm_ptr(xc_shm_t *shm) /* {{{ */ 286 { 287 return shm->ptr; 288 } 289 /* }}} */ 289 static XC_SHM_MEMINIT(xc_mmap_meminit) /* {{{ */ 290 { 291 xc_mem_t *mem; 292 if (shm->memoffset + size > shm->size) { 293 zend_error(E_ERROR, "XCache: internal error at %s#%d", __FILE__, __LINE__); 294 return NULL; 295 } 296 mem = (xc_mem_t *) PTR_ADD(shm->ptr, shm->memoffset); 297 shm->memoffset += size; 298 mem->handlers = shm->handlers->memhandlers; 299 mem->handlers->init(shm, mem, size); 300 return mem; 301 } 302 /* }}} */ 303 static XC_SHM_MEMDESTROY(xc_mmap_memdestroy) /* {{{ */ 304 { 305 } 306 /* }}} */ 307 308 static xc_shm_handlers_t xc_shm_mmap_handlers = XC_SHM_HANDLERS(mmap); 309 void xc_shm_mmap_register() /* {{{ */ 310 { 311 CHECK(xc_shm_mmap_handlers.memhandlers = xc_mem_scheme_find("mem"), "cannot find mem handlers"); 312 if (xc_shm_scheme_register("mmap", &xc_shm_mmap_handlers) == 0) { 313 zend_error(E_ERROR, "XCache: failed to register mmap shm_scheme"); 314 } 315 err: 316 return; 317 } 318 /* }}} */ -
trunk/processor/head.m4
r103 r148 288 288 289 289 /* mem :) */ 290 processor.p = (char *) xc_mem_malloc(src->cache->mem, processor.size);290 processor.p = (char *) src->cache->mem->handlers->malloc(src->cache->mem, processor.size); 291 291 if (processor.p == NULL) { 292 292 dst = NULL; -
trunk/processor/main.m4
r90 r148 118 118 define(`FIXPOINTER', `FIXPOINTER_EX(`$1', `dst->$2')') 119 119 define(`FIXPOINTER_EX', `IFSTORE(` 120 $2 = ($1 *) xc_shm_to_readonly(processor->xce_src->cache->shm, (char *)$2);120 $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readonly(processor->xce_src->cache->shm, (char *)$2); 121 121 ')') 122 122 define(`UNFIXPOINTER', `UNFIXPOINTER_EX(`$1', `dst->$2')') 123 123 define(`UNFIXPOINTER_EX', `IFSTORE(` 124 $2 = ($1 *) xc_shm_to_readwrite(processor->xce_src->cache->shm, (char *)$2);124 $2 = ($1 *) processor->xce_src->cache->shm->handlers->to_readwrite(processor->xce_src->cache->shm, (char *)$2); 125 125 ')') 126 126 dnl }}} -
trunk/utils.c
r131 r148 404 404 int i; 405 405 Bucket *b; 406 zend_llist_position lpos;407 zend_file_handle *handle;408 406 409 407 #ifdef HAVE_XCACHE_CONSTANT -
trunk/xc_shm.h
r137 r148 2 2 typedef size_t xc_shmsize_t; 3 3 4 int xc_shm_can_readonly(xc_shm_t *shm); 5 int xc_shm_is_readwrite(xc_shm_t *shm, const void *p); 6 int xc_shm_is_readonly(xc_shm_t *shm, const void *p); 7 void *xc_shm_to_readwrite(xc_shm_t *shm, void *p); 8 void *xc_shm_to_readonly(xc_shm_t *shm, void *p); 4 #include "mem.h" 9 5 10 void *xc_shm_ptr(xc_shm_t *shm); 6 /* shm */ 7 #define XC_SHM_CAN_READONLY(func) int func(xc_shm_t *shm) 8 #define XC_SHM_IS_READWRITE(func) int func(xc_shm_t *shm, const void *p) 9 #define XC_SHM_IS_READONLY(func) int func(xc_shm_t *shm, const void *p) 10 #define XC_SHM_TO_READWRITE(func) void *func(xc_shm_t *shm, void *p) 11 #define XC_SHM_TO_READONLY(func) void *func(xc_shm_t *shm, void *p) 11 12 12 xc_shm_t *xc_shm_init(const char *path, xc_shmsize_t size, zend_bool readonly_protection); 13 #define XC_SHM_INIT(func) xc_shm_t *func(xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2) 14 #define XC_SHM_DESTROY(func) void func(xc_shm_t *shm) 15 16 #define XC_SHM_MEMINIT(func) xc_mem_t *func(xc_shm_t *shm, xc_memsize_t size) 17 #define XC_SHM_MEMDESTROY(func) void func(xc_mem_t *mem) 18 19 #define XC_SHM_HANDLERS(name) { \ 20 NULL \ 21 , xc_##name##_can_readonly \ 22 , xc_##name##_is_readwrite \ 23 , xc_##name##_is_readonly \ 24 , xc_##name##_to_readwrite \ 25 , xc_##name##_to_readonly \ 26 \ 27 , xc_##name##_init \ 28 , xc_##name##_destroy \ 29 \ 30 , xc_##name##_meminit \ 31 , xc_##name##_memdestroy \ 32 } 33 34 typedef struct { 35 const xc_mem_handlers_t *memhandlers; 36 XC_SHM_CAN_READONLY((*can_readonly)); 37 XC_SHM_IS_READWRITE((*is_readwrite)); 38 XC_SHM_IS_READONLY((*is_readonly)); 39 XC_SHM_TO_READWRITE((*to_readwrite)); 40 XC_SHM_TO_READONLY((*to_readonly)); 41 XC_SHM_INIT((*init)); 42 XC_SHM_DESTROY((*destroy)); 43 44 XC_SHM_MEMINIT((*meminit)); 45 XC_SHM_MEMDESTROY((*memdestroy)); 46 } xc_shm_handlers_t; 47 48 49 #ifndef XC_SHM_IMPL 50 struct _xc_shm_t { 51 const xc_shm_handlers_t *handlers; 52 }; 53 #endif 54 55 void xc_shm_init_modules(); 56 int xc_shm_scheme_register(const char *name, const xc_shm_handlers_t *handlers); 57 const xc_shm_handlers_t *xc_shm_scheme_find(const char *name); 58 59 xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2); 13 60 void xc_shm_destroy(xc_shm_t *shm); -
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 -
trunk/xcache.h
r114 r148 16 16 #include <config.h> 17 17 #endif 18 #include "myshm.h" 19 #include "mem.h" 18 #include "xc_shm.h" 20 19 #include "lock.h" 21 20
Note: See TracChangeset
for help on using the changeset viewer.

