diff options
Diffstat (limited to 'source/fitz/store.c')
-rw-r--r-- | source/fitz/store.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/source/fitz/store.c b/source/fitz/store.c index 2013af8c..d7c04241 100644 --- a/source/fitz/store.c +++ b/source/fitz/store.c @@ -13,6 +13,7 @@ struct fz_item_s const fz_store_type *type; }; +/* Every entry in fz_store is protected by the alloc lock */ struct fz_store_s { int refs; @@ -30,7 +31,6 @@ struct fz_store_s size_t max; size_t size; - /* Protected by the reap lock */ int defer_reap_count; int needs_reaping; }; @@ -93,8 +93,8 @@ void *fz_keep_key_storable(fz_context *ctx, const fz_key_storable *sc) } /* - Entered with FZ_LOCK_ALLOC and FZ_LOCK_REAP held. - Drops FZ_LOCK_ALLOC and FZ_LOCK_REAP. + Entered with FZ_LOCK_ALLOC held. + Drops FZ_LOCK_ALLOC. */ static void do_reap(fz_context *ctx) @@ -109,7 +109,6 @@ do_reap(fz_context *ctx) } fz_assert_lock_held(ctx, FZ_LOCK_ALLOC); - fz_assert_lock_held(ctx, FZ_LOCK_REAP); ctx->store->needs_reaping = 0; @@ -152,7 +151,6 @@ do_reap(fz_context *ctx) remove = item; } fz_unlock(ctx, FZ_LOCK_ALLOC); - fz_unlock(ctx, FZ_LOCK_REAP); /* Now drop the remove chain */ for (item = remove; item != NULL; item = remove) @@ -188,11 +186,9 @@ int fz_drop_key_storable(fz_context *ctx, const fz_key_storable *sc) drop = --s->storable.refs == 0; if (!drop && s->storable.refs == s->store_key_refs) { - fz_lock(ctx, FZ_LOCK_REAP); if (ctx->store->defer_reap_count > 0) { ctx->store->needs_reaping = 1; - fz_unlock(ctx, FZ_LOCK_REAP); } else { @@ -246,7 +242,7 @@ int fz_drop_key_storable_key(fz_context *ctx, const fz_key_storable *sc) int drop; if (s == NULL) - return; + return 0; if (s->storable.refs > 0) (void)Memento_dropRef(s); @@ -484,19 +480,13 @@ fz_store_item(fz_context *ctx, void *key, void *val_, size_t itemsize, const fz_ while (size > store->max) { size_t saved; - int relock = 0; /* First, do any outstanding reaping, even if defer_reap_count > 0 */ - fz_lock(ctx, FZ_LOCK_REAP); if (store->needs_reaping) { do_reap(ctx); /* Drops alloc lock */ - relock = 1; - } - else - fz_unlock(ctx, FZ_LOCK_REAP); - if (relock) fz_lock(ctx, FZ_LOCK_ALLOC); + } size = store->size + itemsize; if (size <= store->max) break; @@ -910,9 +900,9 @@ void fz_defer_reap_start(fz_context *ctx) if (ctx->store == NULL) return; - fz_lock(ctx, FZ_LOCK_REAP); + fz_lock(ctx, FZ_LOCK_ALLOC); ctx->store->defer_reap_count++; - fz_unlock(ctx, FZ_LOCK_REAP); + fz_unlock(ctx, FZ_LOCK_ALLOC); } void fz_defer_reap_end(fz_context *ctx) @@ -923,14 +913,10 @@ void fz_defer_reap_end(fz_context *ctx) return; fz_lock(ctx, FZ_LOCK_ALLOC); - fz_lock(ctx, FZ_LOCK_REAP); --ctx->store->defer_reap_count; reap = ctx->store->defer_reap_count == 0 && ctx->store->needs_reaping; if (reap) - do_reap(ctx); /* Drops FZ_LOCK_ALLOC and FZ_LOCK_REAP*/ + do_reap(ctx); /* Drops FZ_LOCK_ALLOC */ else - { - fz_unlock(ctx, FZ_LOCK_REAP); fz_unlock(ctx, FZ_LOCK_ALLOC); - } } |