From ce8dd001bf8ee83679a1643df0caa54ae32c4128 Mon Sep 17 00:00:00 2001 From: Unbit Date: Fri, 23 Aug 2013 11:06:24 +0200 Subject: [PATCH] ported uwsgi.cache_keys to pypy --- core/cache.c | 12 ++++++++++++ plugins/pypy/pypy_setup.py | 34 ++++++++++++++++++++++++++++++++++ uwsgi.h | 3 +++ 3 files changed, 49 insertions(+) diff --git a/core/cache.c b/core/cache.c index 99e0c6ee..7612c113 100644 --- a/core/cache.c +++ b/core/cache.c @@ -1942,3 +1942,15 @@ struct uwsgi_cache_item *uwsgi_cache_keys(struct uwsgi_cache *uc, uint64_t *pos, (*pos)++; return NULL; } + +void uwsgi_cache_rlock(struct uwsgi_cache *uc) { + uwsgi_rlock(uc->lock); +} + +void uwsgi_cache_rwunlock(struct uwsgi_cache *uc) { + uwsgi_rwunlock(uc->lock); +} + +char *uwsgi_cache_item_key(struct uwsgi_cache_item *uci) { + return uci->key; +} diff --git a/plugins/pypy/pypy_setup.py b/plugins/pypy/pypy_setup.py index 4b814eae..1f139acc 100644 --- a/plugins/pypy/pypy_setup.py +++ b/plugins/pypy/pypy_setup.py @@ -125,6 +125,20 @@ struct uwsgi_buffer { ...; }; +struct uwsgi_lock_item { + ...; +}; + +struct uwsgi_cache { + struct uwsgi_lock_item *lock; + ...; +}; + +struct uwsgi_cache_item { + uint64_t keysize; + ...; +}; + struct uwsgi_server { char hostname[]; int mywid; @@ -184,6 +198,11 @@ int uwsgi_cache_magic_set(char *, uint16_t, char *, uint64_t, uint64_t, uint64_t int uwsgi_cache_magic_del(char *, uint16_t, char *); int uwsgi_cache_magic_exists(char *, uint16_t, char *); int uwsgi_cache_magic_clear(char *); +struct uwsgi_cache *uwsgi_cache_by_name(char *); +void uwsgi_cache_rlock(struct uwsgi_cache *); +void uwsgi_cache_rwunlock(struct uwsgi_cache *); +char *uwsgi_cache_item_key(struct uwsgi_cache_item *); +struct uwsgi_cache_item *uwsgi_cache_keys(struct uwsgi_cache *, uint64_t *, struct uwsgi_cache_item **); int uwsgi_add_file_monitor(uint8_t, char *); int uwsgi_add_timer(uint8_t, int); @@ -541,6 +560,21 @@ def uwsgi_pypy_uwsgi_cache_del(key, cache=ffi.NULL): raise Exception('unable to delete item from the cache') uwsgi.cache_del = uwsgi_pypy_uwsgi_cache_del +def uwsgi_pypy_uwsgi_cache_keys(cache=ffi.NULL): + uc = lib.uwsgi_cache_by_name(cache) + if uc == ffi.NULL: + raise Exception('no local uWSGI cache available') + l = [] + lib.uwsgi_cache_rlock(uc) + pos = ffi.new('uint64_t *') + uci = ffi.new('struct uwsgi_cache_item **') + while True: + uci[0] = lib.uwsgi_cache_keys(uc, pos, uci) + if uci[0] == ffi.NULL: break + l.append(ffi.string(lib.uwsgi_cache_item_key(uci[0]), uci[0].keysize)) + lib.uwsgi_cache_rwunlock(uc) + return l +uwsgi.cache_keys = uwsgi_pypy_uwsgi_cache_keys def uwsgi_pypy_uwsgi_add_timer(signum, secs): if lib.uwsgi_add_timer(signum, secs) < 0: diff --git a/uwsgi.h b/uwsgi.h index 64114683..ff02f0a5 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -4151,6 +4151,9 @@ void uwsgi_exit(int) __attribute__ ((__noreturn__)); void uwsgi_fallback_config(); struct uwsgi_cache_item *uwsgi_cache_keys(struct uwsgi_cache *, uint64_t *, struct uwsgi_cache_item **); +void uwsgi_cache_rlock(struct uwsgi_cache *); +void uwsgi_cache_rwunlock(struct uwsgi_cache *); +char *uwsgi_cache_item_key(struct uwsgi_cache_item *); #ifdef __cplusplus }