Changeset 1199
- Timestamp:
- 12/17/2012 11:18:22 AM (5 months ago)
- Location:
- trunk
- Files:
-
- 5 modified
-
ChangeLog (modified) (1 diff)
-
NEWS (modified) (1 diff)
-
mod_cacher/xc_cacher.c (modified) (1 diff)
-
xcache/xc_lock.c (modified) (11 diffs)
-
xcache/xc_lock.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r1196 r1199 7 7 * improve compatibility with "the ionCube PHP Loader", Zend Optimizer 8 8 * fix random crash when cache is reinitialized yet failed (Thanks to Brad Baker for generating crash dump) 9 * fix ZTS thead safe 9 10 10 11 3.0.0 2012-10-29 -
trunk/NEWS
r1189 r1199 3 3 ======== 4 4 * bug fixes 5 * fix ZTS thead safe 5 6 * improve compatibility with "the ionCube PHP Loader", Zend Optimizer 6 7 * improve stability -
trunk/mod_cacher/xc_cacher.c
r1194 r1199 2656 2656 CHECK(cache->cached->phps = allocator->vtable->calloc(allocator, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); 2657 2657 } 2658 CHECK(cache->lck = xc_lock_init(NULL ), "can't create lock");2658 CHECK(cache->lck = xc_lock_init(NULL, 0), "can't create lock"); 2659 2659 2660 2660 cache->hcache = hcache; -
trunk/xcache/xc_lock.c
r1198 r1199 6 6 #ifdef ZEND_WIN32 7 7 # include <process.h> 8 #else 9 # include <unistd.h> 10 # include <fcntl.h> 11 # include <errno.h> 8 12 #endif 9 13 … … 23 27 NULL) 24 28 #endif 25 #include "xc_lock.h" 26 27 struct _xc_lock_t { 29 30 typedef struct { 28 31 HANDLE fd; 29 32 char *pathname; 30 }; 31 33 } xc_fcntl_lock_t; 34 35 /* {{{ fcntl lock impl */ 32 36 #ifndef ZEND_WIN32 33 # include <unistd.h>34 # include <fcntl.h>35 # include <errno.h>36 37 # define LCK_WR F_WRLCK 37 38 # define LCK_RD F_RDLCK 38 39 # define LCK_UN F_UNLCK 39 40 # define LCK_NB 0 40 static inline int dolock(xc_ lock_t *lck, int type) /* {{{ */41 static inline int dolock(xc_fcntl_lock_t *lck, int type) 41 42 { 42 43 int ret; … … 54 55 return ret; 55 56 } 56 /* }}} */57 57 #else 58 58 … … 69 69 # define LCK_UN 0 70 70 # define LCK_NB LOCKFILE_FAIL_IMMEDIATELY 71 static inline int dolock(xc_ lock_t *lck, int type) /* {{{ */71 static inline int dolock(xc_fcntl_lock_t *lck, int type) 72 72 { 73 73 static OVERLAPPED offset = {0, 0, 0, 0, NULL}; … … 80 80 } 81 81 } 82 /* }}} */ 83 #endif 84 85 xc_lock_t *xc_fcntl_init(const char *pathname) /* {{{ */82 #endif 83 /* }}} */ 84 85 static zend_bool xc_fcntl_init(xc_fcntl_lock_t *lck, const char *pathname) /* {{{ */ 86 86 { 87 87 HANDLE fd; 88 xc_lock_t *lck;89 88 int size; 90 89 char *myname; … … 114 113 115 114 if (fd != INVALID_HANDLE_VALUE) { 116 lck = malloc(sizeof(lck[0]));117 115 118 116 #ifndef __CYGWIN__ … … 133 131 } 134 132 135 return lck ;136 } 137 /* }}} */ 138 void xc_fcntl_destroy(xc_lock_t *lck) /* {{{ */133 return lck ? 1 : 0; 134 } 135 /* }}} */ 136 static void xc_fcntl_destroy(xc_fcntl_lock_t *lck) /* {{{ */ 139 137 { 140 138 close(lck->fd); … … 143 141 #endif 144 142 free(lck->pathname); 145 free(lck); 146 } 147 /* }}} */ 148 void xc_fcntl_lock(xc_lock_t *lck) /* {{{ */ 143 } 144 /* }}} */ 145 static void xc_fcntl_lock(xc_fcntl_lock_t *lck) /* {{{ */ 149 146 { 150 147 if (dolock(lck, LCK_WR) < 0) { … … 153 150 } 154 151 /* }}} */ 155 void xc_fcntl_rdlock(xc_lock_t *lck) /* {{{ */152 static void xc_fcntl_rdlock(xc_fcntl_lock_t *lck) /* {{{ */ 156 153 { 157 154 if (dolock(lck, LCK_RD) < 0) { … … 160 157 } 161 158 /* }}} */ 162 void xc_fcntl_unlock(xc_lock_t *lck) /* {{{ */159 static void xc_fcntl_unlock(xc_fcntl_lock_t *lck) /* {{{ */ 163 160 { 164 161 if (dolock(lck, LCK_UN) < 0) { … … 167 164 } 168 165 /* }}} */ 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 180 181 struct _xc_lock_t { 182 #ifdef XC_LOCK_UNSUED 183 int dummy; 184 #else 185 # ifdef ZTS 186 MUTEX_T tsrm_mutex; 187 # endif 188 189 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 190 # ifdef ZTS 191 zend_bool use_fcntl; 192 # endif 193 xc_fcntl_lock_t fcntl_lock; 194 # endif 195 #endif 196 }; 197 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 # ifdef ZTS 204 xc_lock_t *lck = malloc(sizeof(xc_lock_t)); 205 # if defined(PTHREADS) 206 pthread_mutexattr_t psharedm; 207 pthread_mutexattr_init(&psharedm); 208 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 # else 212 lck->tsrm_mutex = tsrm_mutex_alloc(); 213 # endif 214 # endif 215 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 216 # ifdef ZTS 217 lck->use_fcntl = interprocess; 218 if (lck->use_fcntl) 219 # 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) /* {{{ */ 227 { 228 #ifdef XC_LOCK_UNSUED 229 /* do nothing */ 230 #else 231 # ifdef ZTS 232 tsrm_mutex_free(lck->tsrm_mutex); 233 # endif 234 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 235 # ifdef ZTS 236 if (lck->use_fcntl) 237 # 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 { 246 #ifdef XC_LOCK_UNSUED 247 #else 248 # ifdef ZTS 249 if (tsrm_mutex_lock(lck->tsrm_mutex) < 0) { 250 zend_error(E_ERROR, "xc_lock failed errno:%d", errno); 251 } 252 # endif 253 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 254 # ifdef ZTS 255 if (lck->use_fcntl) 256 # endif 257 xc_fcntl_lock(&lck->fcntl_lock); 258 # endif 259 #endif 260 } 261 /* }}} */ 262 void xc_rdlock(xc_lock_t *lck) /* {{{ */ 263 { 264 #ifdef XC_LOCK_UNSUED 265 #else 266 # ifdef ZTS 267 if (tsrm_mutex_lock(lck->tsrm_mutex) < 0) { 268 zend_error(E_ERROR, "xc_rdlock failed errno:%d", errno); 269 } 270 # endif 271 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 272 # ifdef ZTS 273 if (lck->use_fcntl) 274 # endif 275 xc_fcntl_lock(&lck->fcntl_lock); 276 # endif 277 #endif 278 } 279 /* }}} */ 280 void xc_unlock(xc_lock_t *lck) /* {{{ */ 281 { 282 #ifdef XC_LOCK_UNSUED 283 #else 284 # ifndef XC_INTERPROCESS_LOCK_IMPLEMENTED 285 # ifdef ZTS 286 if (lck->use_fcntl) 287 # endif 288 xc_fcntl_unlock(&lck->fcntl_lock); 289 # endif 290 #endif 291 # ifdef ZTS 292 if (tsrm_mutex_unlock(lck->tsrm_mutex) < 0) { 293 zend_error(E_ERROR, "xc_unlock failed errno:%d", errno); 294 } 295 # endif 296 } 297 /* }}} */ -
trunk/xcache/xc_lock.h
r1044 r1199 8 8 typedef struct _xc_lock_t xc_lock_t; 9 9 10 xc_lock_t *xc_fcntl_init(const char *pathname); 11 void xc_fcntl_destroy(xc_lock_t *lck); 12 void xc_fcntl_lock(xc_lock_t *lck); 13 void xc_fcntl_unlock(xc_lock_t *lck); 14 15 #define xc_lock_init(name) xc_fcntl_init(name) 16 #define xc_lock_destroy(fd) xc_fcntl_destroy(fd) 17 #define xc_lock(fd) xc_fcntl_lock(fd) 18 #define xc_unlock(fd) xc_fcntl_unlock(fd) 10 xc_lock_t *xc_lock_init(const char *pathname, int interprocess /* only with ZTS */); 11 void xc_lock_destroy(xc_lock_t *lck); 12 void xc_lock(xc_lock_t *lck); 13 void xc_unlock(xc_lock_t *lck); 19 14 20 15 #endif /* XC_LOCK_H_1913F3DED68715D7CDA5A055E79FE0FF */

