Re: cvs: pecl /apc apc_cache.c
| From: | Rasmus Lerdorf | Date: | Mon, 23 Oct 2006 15:14:30 +0000 |
| Subject: | Re: cvs: pecl /apc apc_cache.c | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-4279@lists.php.net to get a copy of this message | ||
Really? Was that actually happening?
Gopal Vijayaraghavan wrote:
gopalv Mon Oct 23 12:50:55 2006 UTCModified files: /pecl/apc apc_cache.c Log: Use volatiles to prevent compiler optimizers from re-ordering code out of locked segments. http://cvs.php.net/viewvc.cgi/pecl/apc/apc_cache.c?r1=3.125&r2=3.126&diff_format=uIndex: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.125 pecl/apc/apc_cache.c:3.126 --- pecl/apc/apc_cache.c:3.125 Thu Sep 28 21:22:09 2006 +++ pecl/apc/apc_cache.c Mon Oct 23 12:50:54 2006 @@ -28,7 +28,7 @@ */ -/* $Id: apc_cache.c,v 3.125 2006/09/28 21:22:09 shire Exp $ */ +/* $Id: apc_cache.c,v 3.126 2006/10/23 12:50:54 gopalv Exp $ */ #include "apc_cache.h" #include "apc_lock.h" @@ -546,6 +546,7 @@ apc_cache_entry_t* apc_cache_find(apc_cache_t* cache, apc_cache_key_t key, time_t t) {slot_t** slot; + volatile apc_cache_entry_t* value = NULL; LOCK(cache); if(key.type == APC_CACHE_KEY_FILE) slot = &cache->slots[hash(key) % cache->num_slots];@@ -566,11 +567,9 @@(*slot)->access_time = t; prevent_garbage_collection((*slot)->value); cache->header->num_hits++; - if(1) { - apc_cache_entry_t* value = (*slot)->value; - UNLOCK(cache); - return value; - } + value = (*slot)->value; + UNLOCK(cache); + return (apc_cache_entry_t*)value; } } else { /* APC_CACHE_KEY_FPFILE */ if(!memcmp((*slot)->key.data.fpfile.fullpath, key.data.fpfile.fullpath, key.data.fpfile.fullpath_len+1)) {@@ -580,11 +579,9 @@(*slot)->access_time = t; prevent_garbage_collection((*slot)->value); cache->header->num_hits++; - if(1) { - apc_cache_entry_t* value = (*slot)->value; - UNLOCK(cache); - return value; - } + value = (*slot)->value; + UNLOCK(cache); + return (apc_cache_entry_t*)value; } } }@@ -600,6 +597,7 @@ apc_cache_entry_t* apc_cache_user_find(apc_cache_t* cache, char *strkey, int keylen, time_t t) {slot_t** slot; + volatile apc_cache_entry_t* value = NULL; LOCK(cache); @@ -619,11 +617,9 @@ (*slot)->access_time = t; cache->header->num_hits++; - if(1) { - apc_cache_entry_t * value = (*slot)->value; - UNLOCK(cache); - return value; - } + value = (*slot)->value; + UNLOCK(cache); + return (apc_cache_entry_t*)value; } slot = &(*slot)->next; }