Changeset 148 for trunk/mmap.c
- Timestamp:
- 09/09/2006 02:56:44 AM (7 years ago)
- Files:
-
- 1 modified
-
trunk/mmap.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 /* }}} */

