summaryrefslogtreecommitdiff
path: root/src/stat_cache.c
diff options
context:
space:
mode:
authorJan Kneschke <jan@kneschke.de>2005-08-29 10:44:00 +0000
committerJan Kneschke <jan@kneschke.de>2005-08-29 10:44:00 +0000
commitecb30c4eeca940de9f67dfb2cfad0c6880cbab01 (patch)
tree4f45ff72b74527cf361513f2a2a4e2377aa91912 /src/stat_cache.c
parenta3e25bf8ed4cfa496ac8839ab932bd38abbfec3e (diff)
downloadlighttpd-git-ecb30c4eeca940de9f67dfb2cfad0c6880cbab01.tar.gz
reverted last chngeset and added asserts() that all inserts and deletes are working
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@637 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src/stat_cache.c')
-rw-r--r--src/stat_cache.c79
1 files changed, 69 insertions, 10 deletions
diff --git a/src/stat_cache.c b/src/stat_cache.c
index 30f23904..b428aad0 100644
--- a/src/stat_cache.c
+++ b/src/stat_cache.c
@@ -9,6 +9,7 @@
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
+#include <assert.h>
#include "log.h"
#include "stat_cache.h"
@@ -156,24 +157,38 @@ static void fam_dir_entry_free(void *data) {
void stat_cache_free(stat_cache *sc) {
while (sc->files) {
+ int osize;
splay_tree *node = sc->files;
+
+ osize = sc->files->size;
stat_cache_entry_free(node->data);
sc->files = splaytree_delete(sc->files, node->key);
- free(node);
+ if (osize == 1) {
+ assert(NULL == sc->files);
+ } else {
+ assert(osize == (sc->files->size + 1));
+ }
}
buffer_free(sc->dir_name);
#ifdef HAVE_FAM_H
while (sc->dirs) {
+ int osize;
splay_tree *node = sc->dirs;
-
+
+ osize = sc->dirs->size;
+
fam_dir_entry_free(node->data);
sc->dirs = splaytree_delete(sc->dirs, node->key);
- free(node);
+ if (osize == 1) {
+ assert(NULL == sc->dirs);
+ } else {
+ assert(osize == (sc->dirs->size + 1));
+ }
}
if (sc->fam) {
@@ -256,11 +271,16 @@ handler_t stat_cache_handle_fdevent(void *_srv, void *_fce, int revent) {
node = sc->dirs;
if (node && (node->key == ndx)) {
- fam_dir_entry_free(node->data);
+ int osize = sc->dirs->size;
+ fam_dir_entry_free(node->data);
sc->dirs = splaytree_delete(sc->dirs, ndx);
- free(node);
+ if (osize == 1) {
+ assert(NULL == sc->dirs);
+ } else {
+ assert(osize == (sc->dirs->size + 1));
+ }
}
break;
default:
@@ -342,11 +362,27 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
sce = file_node->data;
- if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_SIMPLE) {
- if (sce->stat_ts == srv->cur_ts) {
- *ret_sce = sce;
- return HANDLER_GO_ON;
+ /* check if the name is the same, we might have a collision */
+
+ if (buffer_is_equal(name, sce->name)) {
+ if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_SIMPLE) {
+ if (sce->stat_ts == srv->cur_ts) {
+ *ret_sce = sce;
+ return HANDLER_GO_ON;
+ }
}
+ } else {
+ /* oops, a collision,
+ *
+ * file_node is used by the FAM check below to see if we know this file
+ * and if we can save a stat().
+ *
+ * BUT, the sce is not reset here as the entry into the cache is ok, we
+ * it is just not pointing to our requested file.
+ *
+ * */
+
+ file_node = NULL;
}
}
@@ -389,10 +425,19 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
size_t k;
if (NULL == sce) {
+ int osize = 0;
+
+ if (sc->files) {
+ osize = sc->files->size;
+ }
+
sce = stat_cache_entry_init();
buffer_copy_string_buffer(sce->name, name);
sc->files = splaytree_insert(sc->files, file_ndx, sce);
+
+ assert(sc->files);
+ assert(osize == (sc->files->size - 1));
}
sce->st = st;
@@ -448,7 +493,15 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
fam_dir_entry_free(fam_dir);
} else {
+ int osize = 0;
+
+ if (sc->dirs) {
+ osize = sc->dirs->size;
+ }
+
sc->dirs = splaytree_insert(sc->dirs, dir_ndx, fam_dir);
+ assert(sc->dirs);
+ assert(osize == (sc->dirs->size - 1));
}
} else {
fam_dir = dir_node->data;
@@ -516,10 +569,16 @@ int stat_cache_trigger_cleanup(server *srv) {
node = sc->files;
if (node && (node->key == ndx)) {
+ int osize = sc->files->size;
+
stat_cache_entry_free(node->data);
sc->files = splaytree_delete(sc->files, ndx);
- free(node);
+ if (osize == 1) {
+ assert(NULL == sc->files);
+ } else {
+ assert(osize == (sc->files->size + 1));
+ }
}
}