Index: tags/2007080101/fastxsl.c =================================================================== --- tags/2007080101/fastxsl.c (revision 26) +++ tags/2007080101/fastxsl.c (revision 33) @@ -346,4 +346,26 @@ #endif +#ifdef F_SETLK +#define ACQUIRE(lockfd) do { \ + struct flock lock; \ + lock.l_start = 0; \ + lock.l_whence = SEEK_SET; \ + lock.l_len = 0; \ + lock.l_type = F_WRLCK; \ + fcntl((lockfd), F_SETLKW, &lock); \ +} while(0) +#define RELEASE(lockfd) do { \ + struct flock lock; \ + lock.l_start = 0; \ + lock.l_whence = SEEK_SET; \ + lock.l_len = 0; \ + lock.l_type = F_UNLCK; \ + fcntl((lockfd), F_SETLK, &lock); \ +} while(0) +#else +#define ACQUIRE(lockfd) flock((lockfd), LOCK_EX) +#define RELEASE(lockfd) flock((lockfd), LOCK_UN) +#endif + #ifdef FASTXSL_MM /* {{{ proto void fastxsl_CachedDocumentFunction(xmlXPathParserContextPtr ctxt, int nargs) @@ -360,11 +382,5 @@ struct stat sb; php_ss_wrapper *ss_wrapper; -#ifdef F_SETLK - struct flock lock; - - lock.l_start = 0; - lock.l_whence = SEEK_SET; - lock.l_len = 0; -#endif + xmlXPathStringFunction(ctxt, 1); if (ctxt->value->type != XPATH_STRING) { @@ -396,10 +412,5 @@ sb.st_mtime = 0; } -#ifdef F_SETLK - lock.l_type = F_WRLCK; - fcntl(lockfd, F_SETLKW, &lock); -#else - flock(lockfd, LOCK_EX); -#endif + ACQUIRE(lockfd); mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RW); ss_wrapper = fl_hash_find(FASTXSL_G(cache)->table, ss_filename, ss_filename_len); @@ -445,10 +456,5 @@ } if (!ss_wrapper) { -#ifdef F_SETLK - lock.l_type = F_UNLCK; - fcntl(lockfd, F_SETLK, &lock); -#else - flock(lockfd, LOCK_UN); -#endif + RELEASE(lockfd); close(lockfd); //xmlCleanupParserr(); @@ -504,10 +510,5 @@ //xmlCleanupParserr(); if (!ss_wrapper) { -#ifdef F_SETLK - lock.l_type = F_UNLCK; - fcntl(lockfd, F_SETLK, &lock); -#else - flock(lockfd, LOCK_UN); -#endif + RELEASE(lockfd); close(lockfd); goto error; @@ -519,10 +520,5 @@ //xmlCleanupParserr(); Xml_UseAllocationFunctions(); -#ifdef F_SETLK - lock.l_type = F_UNLCK; - fcntl(lockfd, F_SETLK, &lock); -#else - flock(lockfd, LOCK_UN); -#endif + RELEASE(lockfd); close(lockfd); @@ -817,12 +813,4 @@ struct stat sb; int lockfd; -#ifdef F_SETLK - struct flock lock; - - lock.l_start = 0; - lock.l_whence = SEEK_SET; - lock.l_len = 0; -#endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|z", &ss_filename, &ss_filename_len, @@ -862,10 +850,5 @@ sb.st_mtime = 0; } -#ifdef F_SETLK - lock.l_type = F_WRLCK; - fcntl(lockfd, F_SETLKW, &lock); -#else - flock(lockfd, LOCK_EX); -#endif + ACQUIRE(lockfd); mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RW); ss_wrapper = fl_hash_find(FASTXSL_G(cache)->table, ss_filename, ss_filename_len); @@ -877,10 +860,5 @@ inshm = 0; if (!ss_wrapper) { -#ifdef F_SETLK - lock.l_type = F_UNLCK; - fcntl(lockfd, F_SETLK, &lock); -#else - flock(lockfd, LOCK_UN); -#endif + RELEASE(lockfd); close(lockfd); //xmlCleanupParserr(); @@ -902,10 +880,5 @@ Xml_UseAllocationFunctions(); if (!ss_wrapper) { -#ifdef F_SETLK - lock.l_type = F_UNLCK; - fcntl(lockfd, F_SETLK, &lock); -#else - flock(lockfd, LOCK_UN); -#endif + RELEASE(lockfd); close(lockfd); _XD_Wrapper_Dtor(result_wrapper); @@ -919,10 +892,5 @@ //xmlCleanupParserr(); Xml_UseAllocationFunctions(); -#ifdef F_SETLK - lock.l_type = F_UNLCK; - fcntl(lockfd, F_SETLK, &lock); -#else - flock(lockfd, LOCK_UN); -#endif + RELEASE(lockfd); close(lockfd);