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 /include/mupdf/fitz/context.h | |
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 'include/mupdf/fitz/context.h')
-rw-r--r-- | include/mupdf/fitz/context.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 79406942..f694bc39 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -457,4 +457,34 @@ fz_unlock(fz_context *ctx, int lock) ctx->locks->unlock(ctx->locks->user, lock); } +static inline void * +fz_keep_imp(fz_context *ctx, void *p, int *refs) +{ + if (p) + { + fz_lock(ctx, FZ_LOCK_ALLOC); + if (*refs > 0) + ++*refs; + fz_unlock(ctx, FZ_LOCK_ALLOC); + } + return p; +} + +static inline int +fz_drop_imp(fz_context *ctx, void *p, int *refs) +{ + if (p) + { + int drop; + fz_lock(ctx, FZ_LOCK_ALLOC); + if (*refs > 0) + drop = --*refs == 0; + else + drop = 0; + fz_unlock(ctx, FZ_LOCK_ALLOC); + return drop; + } + return 0; +} + #endif |