Changeset 1204
- Timestamp:
- 12/17/2012 06:11:58 PM (5 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
mod_cacher/xc_cacher.c (modified) (3 diffs)
-
xcache/xc_lock.c (modified) (6 diffs)
-
xcache/xc_lock.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/mod_cacher/xc_cacher.c
r1201 r1204 41 41 42 42 #define ENTER_LOCK_EX(x) \ 43 xc_lock((x)->lck); \43 LOCK((x)); \ 44 44 zend_try { \ 45 45 do … … 49 49 catched = 1; \ 50 50 } zend_end_try(); \ 51 xc_unlock((x)->lck)51 UNLOCK((x)) 52 52 53 53 #define ENTER_LOCK(x) do { \ … … 2651 2651 } 2652 2652 CHECK(allocator->vtable->init(shm, allocator, memsize), "Failed init allocator"); 2653 CHECK(cache->cached = allocator->vtable->calloc(allocator, 1, sizeof(xc_cached_t)), "c ache OOM");2654 CHECK(cache->cached->entries = allocator->vtable->calloc(allocator, hentry->size, sizeof(xc_entry_t*)), " entries OOM");2653 CHECK(cache->cached = allocator->vtable->calloc(allocator, 1, sizeof(xc_cached_t)), "create cache OOM"); 2654 CHECK(cache->cached->entries = allocator->vtable->calloc(allocator, hentry->size, sizeof(xc_entry_t*)), "create entries OOM"); 2655 2655 if (hphp) { 2656 CHECK(cache->cached->phps = allocator->vtable->calloc(allocator, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); 2657 } 2658 CHECK(cache->lck = xc_lock_init(NULL, 0), "can't create lock"); 2656 CHECK(cache->cached->phps = allocator->vtable->calloc(allocator, hphp->size, sizeof(xc_entry_data_php_t*)), "create phps OOM"); 2657 } 2658 CHECK(cache->lck = allocator->vtable->calloc(allocator, 1, xc_lock_size()), "create lock OOM"); 2659 CHECK(xc_lock_init(cache->lck, NULL, 1), "can't create lock"); 2659 2660 2660 2661 cache->hcache = hcache; -
trunk/xcache/xc_lock.c
r1200 r1204 11 11 # include <errno.h> 12 12 #endif 13 14 /* {{{ detect what lock to use */ 15 #undef XC_INTERPROCESS_LOCK_IMPLEMENTED 16 #undef XC_LOCK_UNSUED 17 18 #ifdef ZEND_WIN32 19 # define XC_INTERPROCESS_LOCK_IMPLEMENTED 20 # ifndef ZTS 21 # define XC_LOCK_UNSUED 22 # endif 23 #endif 24 25 #ifdef _POSIX_THREAD_PROCESS_SHARED 26 # include "../mod_cacher/xc_cache.h" 27 # define XC_INTERPROCESS_LOCK_IMPLEMENTED 28 #endif 29 /* }}} */ 30 31 #ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 13 32 14 33 #ifndef ZEND_WIN32 … … 74 93 75 94 if (type == LCK_UN) { 76 return UnlockFileEx( (HANDLE)lck->fd, 0, 1, 0, &offset);95 return UnlockFileEx(lck->fd, 0, 1, 0, &offset); 77 96 } 78 97 else { 79 return LockFileEx( (HANDLE)lck->fd, type, 0, 1, 0, &offset);98 return LockFileEx(lck->fd, type, 0, 1, 0, &offset); 80 99 } 81 100 } … … 164 183 } 165 184 /* }}} */ 166 167 #undef XC_INTERPROCESS_LOCK_IMPLEMENTED 168 #undef XC_LOCK_UNSUED 169 170 #ifdef ZEND_WIN32 171 # define XC_INTERPROCESS_LOCK_IMPLEMENTED 172 # ifndef ZTS 173 # define XC_LOCK_UNSUED 174 # endif 175 #endif 176 177 #if defined(PTHREADS) 178 # define XC_INTERPROCESS_LOCK_IMPLEMENTED 179 #endif 185 #endif /* XC_INTERPROCESS_LOCK_IMPLEMENTED */ 180 186 181 187 struct _xc_lock_t { … … 187 193 # endif 188 194 195 # ifdef _POSIX_THREAD_PROCESS_SHARED 196 pthread_mutex_t pthread_mutex; 197 # endif 189 198 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 190 199 # ifdef ZTS … … 194 203 # endif 195 204 #endif 205 206 #ifndef NDEBUG 207 zend_bool locked; 208 #endif 196 209 }; 197 210 198 xc_lock_t *xc_lock_init(const char *pathname, int interprocess) /* {{{ */ 199 { 200 #ifdef XC_LOCK_UNSUED 201 return (xc_lock_t *) 1; 202 #else 203 xc_lock_t *lck = malloc(sizeof(xc_lock_t)); 204 # ifdef ZTS 205 # if defined(PTHREADS) 211 size_t xc_lock_size(void) /* {{{ */ 212 { 213 return sizeof(xc_lock_t); 214 } 215 /* }}} */ 216 xc_lock_t *xc_lock_init(xc_lock_t *lck, const char *pathname, unsigned char interprocess) /* {{{ */ 217 { 218 #ifdef ZTS 219 # ifdef _POSIX_THREAD_PROCESS_SHARED 206 220 pthread_mutexattr_t psharedm; 207 221 pthread_mutexattr_init(&psharedm); 208 222 pthread_mutexattr_setpshared(&psharedm, PTHREAD_PROCESS_SHARED); 209 lck->tsrm_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));210 pthread_mutex_init(lck->tsrm_mutex, &psharedm);211 # else223 pthread_mutex_init(&lck->pthread_mutex, &psharedm); 224 lck->tsrm_mutex = &lck->pthread_mutex; 225 # else 212 226 lck->tsrm_mutex = tsrm_mutex_alloc(); 213 # endif 227 # endif 228 #endif 229 230 #ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 231 # ifdef ZTS 232 lck->use_fcntl = interprocess; 233 if (lck->use_fcntl) 234 # endif 235 xc_fcntl_init(&lck->fcntl_lock, pathname); 236 #endif 237 238 #ifndef NDEBUG 239 lck->locked = 0; 240 #endif 241 242 return lck; 243 } 244 /* }}} */ 245 void xc_lock_destroy(xc_lock_t *lck) /* {{{ */ 246 { 247 #ifdef ZTS 248 # ifdef _POSIX_THREAD_PROCESS_SHARED 249 pthread_mutex_destroy(&lck->pthread_mutex); 250 # else 251 tsrm_mutex_free(lck->tsrm_mutex); 252 # endif 253 lck->tsrm_mutex = NULL; 254 #endif 255 256 #ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 257 # ifdef ZTS 258 if (lck->use_fcntl) 259 # endif 260 xc_fcntl_destroy(&lck->fcntl_lock); 261 #endif 262 } 263 /* }}} */ 264 void xc_lock(xc_lock_t *lck) /* {{{ */ 265 { 266 #ifdef XC_LOCK_UNSUED 267 #else 268 # ifdef ZTS 269 if (tsrm_mutex_lock(lck->tsrm_mutex) < 0) { 270 zend_error(E_ERROR, "xc_lock failed errno:%d", errno); 271 } 214 272 # endif 215 273 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 216 274 # ifdef ZTS 217 lck->use_fcntl = interprocess;218 275 if (lck->use_fcntl) 219 276 # endif 220 xc_fcntl_init(&lck->fcntl_lock, pathname); 221 # endif 222 return lck; 223 #endif 224 } 225 /* }}} */ 226 void xc_lock_destroy(xc_lock_t *lck) /* {{{ */ 277 xc_fcntl_lock(&lck->fcntl_lock); 278 # endif 279 #endif 280 281 #ifndef NDEBUG 282 assert(!lck->locked); 283 lck->locked = 1; 284 assert(lck->locked); 285 #endif 286 } 287 /* }}} */ 288 void xc_rdlock(xc_lock_t *lck) /* {{{ */ 227 289 { 228 290 #ifdef XC_LOCK_UNSUED 229 /* do nothing */ 230 #else 231 # ifdef ZTS 232 tsrm_mutex_free(lck->tsrm_mutex); 291 #else 292 # ifdef ZTS 293 if (tsrm_mutex_lock(lck->tsrm_mutex) < 0) { 294 zend_error(E_ERROR, "xc_rdlock failed errno:%d", errno); 295 } 233 296 # endif 234 297 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED … … 236 299 if (lck->use_fcntl) 237 300 # endif 238 xc_fcntl_destroy(&lck->fcntl_lock); 239 # endif 240 free(lck); 241 #endif 242 } 243 /* }}} */ 244 void xc_lock(xc_lock_t *lck) /* {{{ */ 245 { 301 xc_fcntl_lock(&lck->fcntl_lock); 302 # endif 303 #endif 304 305 #ifndef NDEBUG 306 assert(!lck->locked); 307 lck->locked = 1; 308 assert(lck->locked); 309 #endif 310 } 311 /* }}} */ 312 void xc_unlock(xc_lock_t *lck) /* {{{ */ 313 { 314 #ifndef NDEBUG 315 assert(lck->locked); 316 lck->locked = 0; 317 assert(!lck->locked); 318 #endif 319 246 320 #ifdef XC_LOCK_UNSUED 247 321 #else 248 # ifdef ZTS249 if (tsrm_mutex_lock(lck->tsrm_mutex) < 0) {250 zend_error(E_ERROR, "xc_lock failed errno:%d", errno);251 }252 # endif253 322 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 254 323 # ifdef ZTS 255 324 if (lck->use_fcntl) 256 325 # endif 257 xc_fcntl_lock(&lck->fcntl_lock);258 # endif259 #endif260 }261 /* }}} */262 void xc_rdlock(xc_lock_t *lck) /* {{{ */263 {264 #ifdef XC_LOCK_UNSUED265 #else266 # ifdef ZTS267 if (tsrm_mutex_lock(lck->tsrm_mutex) < 0) {268 zend_error(E_ERROR, "xc_rdlock failed errno:%d", errno);269 }270 # endif271 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED272 # ifdef ZTS273 if (lck->use_fcntl)274 # endif275 xc_fcntl_lock(&lck->fcntl_lock);276 # endif277 #endif278 }279 /* }}} */280 void xc_unlock(xc_lock_t *lck) /* {{{ */281 {282 #ifdef XC_LOCK_UNSUED283 #else284 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED285 # ifdef ZTS286 if (lck->use_fcntl)287 # endif288 326 xc_fcntl_unlock(&lck->fcntl_lock); 289 327 # endif -
trunk/xcache/xc_lock.h
r1199 r1204 6 6 #endif /* _MSC_VER > 1000 */ 7 7 8 #include <stdlib.h> 9 8 10 typedef struct _xc_lock_t xc_lock_t; 9 11 10 xc_lock_t *xc_lock_init(const char *pathname, int interprocess /* only with ZTS */); 12 size_t xc_lock_size(void); 13 xc_lock_t *xc_lock_init(xc_lock_t *lck, const char *pathname, unsigned char interprocess /* only with ZTS */); 11 14 void xc_lock_destroy(xc_lock_t *lck); 12 15 void xc_lock(xc_lock_t *lck);

