diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-02-17 10:30:59 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-02-17 18:06:11 +0100 |
commit | 72679561cddc6b2586e596f62492b79dcf9f118d (patch) | |
tree | 25d156aacc2d2ac3e33170ec42b6501edb9b6754 /source/fitz/context.c | |
parent | 6cc97e85489f5e4e39aa185d17ad5e35b09dddb5 (diff) | |
download | mupdf-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/context.c')
-rw-r--r-- | source/fitz/context.c | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/source/fitz/context.c b/source/fitz/context.c index b3ca9b5b..7a2076b7 100644 --- a/source/fitz/context.c +++ b/source/fitz/context.c @@ -9,16 +9,10 @@ struct fz_id_context_s static void fz_drop_id_context(fz_context *ctx) { - int refs; - fz_id_context *id = ctx->id; - - if (id == NULL) + if (!ctx) return; - fz_lock(ctx, FZ_LOCK_ALLOC); - refs = --id->refs; - fz_unlock(ctx, FZ_LOCK_ALLOC); - if (refs == 0) - fz_free(ctx, id); + if (fz_drop_imp(ctx, ctx->id, &ctx->id->refs)) + fz_free(ctx, ctx->id); } static void @@ -32,14 +26,9 @@ fz_new_id_context(fz_context *ctx) static fz_id_context * fz_keep_id_context(fz_context *ctx) { - fz_id_context *id = ctx->id; - - if (id == NULL) + if (!ctx) return NULL; - fz_lock(ctx, FZ_LOCK_ALLOC); - ++id->refs; - fz_unlock(ctx, FZ_LOCK_ALLOC); - return id; + return fz_keep_imp(ctx, ctx->id, &ctx->id->refs); } void @@ -208,12 +197,9 @@ fz_gen_id(fz_context *ctx) { int id; fz_lock(ctx, FZ_LOCK_ALLOC); - /* We'll never wrap around in normal use, but if we *do*, then avoid - * 0. */ + /* We'll never wrap around in normal use, but if we do, then avoid 0. */ do - { id = ++ctx->id->id; - } while (id == 0); fz_unlock(ctx, FZ_LOCK_ALLOC); return id; |