logo       

cvs: pecl /apc apc_cache.c apc_lock.h package.xml: msg#00268

php.pecl.cvs

Subject: cvs: pecl /apc apc_cache.c apc_lock.h package.xml

rasmus Fri Jul 29 17:42:09 2005 EDT

Modified files:
/pecl/apc apc_cache.c apc_lock.h package.xml
Log:
Read locks on cache_find functions that are upgraded to a write lock
only once an entry is found and we need to update counters or potentially
remove the entry.


http://cvs.php.net/diff.php/pecl/apc/apc_cache.c?r1=3.90&r2=3.91&ty=u
Index: pecl/apc/apc_cache.c
diff -u pecl/apc/apc_cache.c:3.90 pecl/apc/apc_cache.c:3.91
--- pecl/apc/apc_cache.c:3.90 Fri Jul 29 16:54:11 2005
+++ pecl/apc/apc_cache.c Fri Jul 29 17:42:07 2005
@@ -28,7 +28,7 @@

*/

-/* $Id: apc_cache.c,v 3.90 2005/07/29 20:54:11 rasmus Exp $ */
+/* $Id: apc_cache.c,v 3.91 2005/07/29 21:42:07 rasmus Exp $ */

#include "apc_cache.h"
#include "apc_lock.h"
@@ -468,12 +468,15 @@
{
slot_t** slot;

- LOCK(cache);
+ RDLOCK(cache);

slot = &cache->slots[hash(key) % cache->num_slots];

while (*slot) {
if (key_equals((*slot)->key.data.file, key.data.file)) {
+#if RDLOCK_AVAILABLE
+ LOCK(cache); /* Upgrade to a write lock */
+#endif
if ((*slot)->key.mtime < key.mtime) {
remove_slot(cache, slot);
break;
@@ -491,6 +494,9 @@
slot = &(*slot)->next;
}

+#if RDLOCK_AVAILABLE
+ LOCK(cache); /* Upgrade to a write lock */
+#endif
cache->header->num_misses++;
UNLOCK(cache);
return NULL;
@@ -502,12 +508,15 @@
{
slot_t** slot;

- LOCK(cache);
+ RDLOCK(cache);

slot = &cache->slots[string_nhash_8(strkey, keylen) % cache->num_slots];

while (*slot) {
if (!strncmp((*slot)->key.data.user.identifier, strkey, keylen)) {
+#if RDLOCK_AVAILABLE
+ LOCK(cache); /* Upgrade to a write lock */
+#endif
/* Check to make sure this entry isn't expired by a hard TTL */
if((*slot)->value->data.user.ttl && ((*slot)->creation_time +
(*slot)->value->data.user.ttl) < t) {
remove_slot(cache, slot);
@@ -525,6 +534,9 @@
slot = &(*slot)->next;
}

+#if RDLOCK_AVAILABLE
+ LOCK(cache); /* Upgrade to a write lock */
+#endif
cache->header->num_misses++;
UNLOCK(cache);
return NULL;
http://cvs.php.net/diff.php/pecl/apc/apc_lock.h?r1=3.10&r2=3.11&ty=u
Index: pecl/apc/apc_lock.h
diff -u pecl/apc/apc_lock.h:3.10 pecl/apc/apc_lock.h:3.11
--- pecl/apc/apc_lock.h:3.10 Thu Jul 28 19:10:32 2005
+++ pecl/apc/apc_lock.h Fri Jul 29 17:42:08 2005
@@ -26,7 +26,7 @@

*/

-/* $Id: apc_lock.h,v 3.10 2005/07/28 23:10:32 rasmus Exp $ */
+/* $Id: apc_lock.h,v 3.11 2005/07/29 21:42:08 rasmus Exp $ */

#ifndef APC_LOCK
#define APC_LOCK
@@ -38,6 +38,7 @@
#endif

#ifdef TSRM_LOCKS
+#define RDLOCK_AVAILABLE 0
/* quick & dirty: use TSRM mutex locks for now */
#define apc_lck_create(a,b,c) (int)tsrm_mutex_alloc()
#define apc_lck_destroy(a) tsrm_mutex_free((MUTEX_T)a)
@@ -45,12 +46,14 @@
#define apc_lck_rdlock(a) tsrm_mutex_lock((MUTEX_T)a)
#define apc_lck_unlock(a) tsrm_mutex_unlock((MUTEX_T)a)
#elif defined(APC_SEM_LOCKS)
+#define RDLOCK_AVAILABLE 0
#define apc_lck_create(a,b,c) apc_sem_create(NULL,(b),(c))
#define apc_lck_destroy(a) apc_sem_destroy(a)
#define apc_lck_lock(a) apc_sem_lock(a)
#define apc_lck_rdlock(a) apc_sem_lock(a)
#define apc_lck_unlock(a) apc_sem_unlock(a)
#else
+#define RDLOCK_AVAILABLE 1
#define apc_lck_create(a,b,c) apc_fcntl_create((a))
#define apc_lck_destroy(a) apc_fcntl_destroy(a)
#define apc_lck_lock(a) apc_fcntl_lock(a)
http://cvs.php.net/diff.php/pecl/apc/package.xml?r1=1.21&r2=1.22&ty=u
Index: pecl/apc/package.xml
diff -u pecl/apc/package.xml:1.21 pecl/apc/package.xml:1.22
--- pecl/apc/package.xml:1.21 Fri Jul 29 17:01:32 2005
+++ pecl/apc/package.xml Fri Jul 29 17:42:08 2005
@@ -37,7 +37,7 @@
Track per-entry memory usage. (Val)
Various apc.php fixes and enhancements. (Ralf, Ilia, Rasmus)
fcntl locking robustness fixes. (Rasmus)
-Shared fcntl read-lock for read-only info functions. (Rasmus)
+Shared read-locks where possible. (Rasmus)
Added file_update_protection configuration parameter. (Rasmus)
Windows ZTS fixes (Frank)
</notes>



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise