diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-02-05 19:40:17 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-02-05 19:40:17 +0000 |
commit | 3958d7b16f0fd54bce0ba9a6992fe773633e7077 (patch) | |
tree | 670a572348987d9733b6babf305b0b4f6e62baf7 | |
parent | 2502359a5b54792715d64229b10c008708c82a2f (diff) | |
download | tor-3958d7b16f0fd54bce0ba9a6992fe773633e7077.tar.gz tor-3958d7b16f0fd54bce0ba9a6992fe773633e7077.zip |
r17898@catbus: nickm | 2008-02-05 14:01:35 -0500
Add (and use) a MAP_DEL_CURRENT macro to augment a non-const variant of MAP_FOREACH.
svn:r13379
-rw-r--r-- | src/common/container.h | 23 | ||||
-rw-r--r-- | src/or/dirserv.c | 18 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/common/container.h b/src/common/container.h index 3b5d72b1c2..305dc0ea0a 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -220,10 +220,33 @@ DECLARE_MAP_FNS(digestmap_t, const char *, digestmap_); prefix##iter_get(key##_iter, &keyvar, &valvar##_voidp); \ valvar = valvar##_voidp; +#define MAP_FOREACH_MODIFY(prefix, map, keytype, keyvar, valtype, valvar) \ + STMT_BEGIN \ + prefix##iter_t *key##_iter; \ + int keyvar##_del=0; \ + for (key##_iter = prefix##iter_init(map); \ + !prefix##iter_done(key##_iter); \ + key##_iter = keyvar##_del ? \ + prefix##iter_next_rmv(map, key##_iter) : \ + prefix##iter_next(map, key##_iter)) { \ + keytype keyvar; \ + void *valvar##_voidp; \ + valtype valvar; \ + keyvar##_del=0; \ + prefix##iter_get(key##_iter, &keyvar, &valvar##_voidp); \ + valvar = valvar##_voidp; + +#define MAP_DEL_CURRENT(keyvar) \ + STMT_BEGIN \ + keyvar##_del = 1; \ + STMT_END + #define MAP_FOREACH_END } STMT_END ; #define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar) \ MAP_FOREACH(digestmap_, map, const char *, keyvar, valtype, valvar) +#define DIGESTMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \ + MAP_FOREACH_MODIFY(digestmap_, map, const char *, keyvar, valtype, valvar) #define DIGESTMAP_FOREACH_END MAP_FOREACH_END void* strmap_set_lc(strmap_t *map, const char *key, void *val); diff --git a/src/or/dirserv.c b/src/or/dirserv.c index e66cb2aa5b..f86bff9e09 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1396,22 +1396,13 @@ dirserv_set_cached_networkstatus_v3(const char *networkstatus, void dirserv_clear_old_networkstatuses(time_t cutoff) { - digestmap_iter_t *iter; - if (!cached_v2_networkstatus) return; - for (iter = digestmap_iter_init(cached_v2_networkstatus); - !digestmap_iter_done(iter); ) { - const char *ident; - void *val; - cached_dir_t *dir; - digestmap_iter_get(iter, &ident, &val); - dir = val; + DIGESTMAP_FOREACH_MODIFY(cached_v2_networkstatus, id, cached_dir_t *, dir) { if (dir->published < cutoff) { char *fname; - iter = digestmap_iter_next_rmv(cached_v2_networkstatus, iter); - fname = networkstatus_get_cache_filename(ident); + fname = networkstatus_get_cache_filename(id); if (file_status(fname) == FN_FILE) { log_info(LD_DIR, "Removing too-old untrusted networkstatus in %s", fname); @@ -1419,10 +1410,9 @@ dirserv_clear_old_networkstatuses(time_t cutoff) } tor_free(fname); cached_dir_decref(dir); - } else { - iter = digestmap_iter_next(cached_v2_networkstatus, iter); + MAP_DEL_CURRENT(id); } - } + } DIGESTMAP_FOREACH_END } /** Remove any v1 info from the directory cache that was published |