summaryrefslogtreecommitdiff
path: root/source/fitz/store.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-02-17 10:30:59 +0100
committerTor Andersson <tor.andersson@artifex.com>2015-02-17 18:06:11 +0100
commit72679561cddc6b2586e596f62492b79dcf9f118d (patch)
tree25d156aacc2d2ac3e33170ec42b6501edb9b6754 /source/fitz/store.c
parent6cc97e85489f5e4e39aa185d17ad5e35b09dddb5 (diff)
downloadmupdf-72679561cddc6b2586e596f62492b79dcf9f118d.tar.xz
Add helper functions to keep/drop reference counts with locking.
Add locks around fz_path and fz_text reference counting.
Diffstat (limited to 'source/fitz/store.c')
-rw-r--r--source/fitz/store.c36
1 files changed, 9 insertions, 27 deletions
diff --git a/source/fitz/store.c b/source/fitz/store.c
index d4cafe15..dd1cb784 100644
--- a/source/fitz/store.c
+++ b/source/fitz/store.c
@@ -56,38 +56,20 @@ fz_new_store_context(fz_context *ctx, unsigned int max)
void *
fz_keep_storable(fz_context *ctx, fz_storable *s)
{
- if (s == NULL)
- return NULL;
- fz_lock(ctx, FZ_LOCK_ALLOC);
- if (s->refs > 0)
- s->refs++;
- fz_unlock(ctx, FZ_LOCK_ALLOC);
- return s;
+ return fz_keep_imp(ctx, s, &s->refs);
}
void
fz_drop_storable(fz_context *ctx, fz_storable *s)
{
- int do_free = 0;
-
- if (s == NULL)
- return;
- fz_lock(ctx, FZ_LOCK_ALLOC);
- if (s->refs < 0)
- {
- /* It's a static object. Dropping does nothing. */
- }
- else if (--s->refs == 0)
- {
- /* If we are dropping the last reference to an object, then
- * it cannot possibly be in the store (as the store always
- * keeps a ref to everything in it, and doesn't drop via
- * this method. So we can simply drop the storable object
- * itself without any operations on the fz_store. */
- do_free = 1;
- }
- fz_unlock(ctx, FZ_LOCK_ALLOC);
- if (do_free)
+ /*
+ If we are dropping the last reference to an object, then
+ it cannot possibly be in the store (as the store always
+ keeps a ref to everything in it, and doesn't drop via
+ this method. So we can simply drop the storable object
+ itself without any operations on the fz_store.
+ */
+ if (fz_drop_imp(ctx, s, &s->refs))
s->drop(ctx, s);
}