summaryrefslogtreecommitdiff
path: root/fitz/fitz.h
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-01-18 15:49:09 +0000
committerRobin Watts <robin.watts@artifex.com>2012-01-19 12:40:24 +0000
commit40f4ed22806b88ba0e26c458915d4695f1f7c201 (patch)
treebacdebee1932d294f8233a8fb14cb86383e5f107 /fitz/fitz.h
parent2c836b57d5295b47655988cf8deaffda731e1c3c (diff)
downloadmupdf-40f4ed22806b88ba0e26c458915d4695f1f7c201.tar.xz
Multi-threading support for MuPDF
When we moved over to a context based system, we laid the foundation for a thread-safe mupdf. This commit should complete that process. Firstly, fz_clone_context is properly implemented so that it makes a new context, but shares certain sections (currently just the allocator, and the store). Secondly, we add locking (to parts of the code that have previously just had placeholder LOCK/UNLOCK comments). Functions to lock and unlock a mutex are added to the allocator structure; omit these (as is the case today) and no multithreading is (safely) possible. The context will refuse to clone if these are not provided. Finally we flesh out the LOCK/UNLOCK comments to be real calls of the functions - unfortunately this requires us to plumb fz_context into the fz_keep_storable function (and all the fz_keep_xxx functions that call it). This is the largest section of the patch. No changes expected to any test files.
Diffstat (limited to 'fitz/fitz.h')
-rw-r--r--fitz/fitz.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index ccfa0bd6..3971f24c 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -120,6 +120,8 @@ struct fz_alloc_context_s
void *(*malloc)(void *, unsigned int);
void *(*realloc)(void *, void *, unsigned int);
void (*free)(void *, void *);
+ void (*lock)(void *);
+ void (*unlock)(void *);
};
/* Default allocator */
@@ -376,6 +378,20 @@ void fz_free_context(fz_context *ctx);
void fz_new_aa_context(fz_context *ctx);
void fz_free_aa_context(fz_context *ctx);
+static inline void
+fz_lock(fz_context *ctx)
+{
+ if (ctx->alloc->lock)
+ ctx->alloc->lock(ctx->alloc->user);
+}
+
+static inline void
+fz_unlock(fz_context *ctx)
+{
+ if (ctx->alloc->unlock)
+ ctx->alloc->unlock(ctx->alloc->user);
+}
+
/*
* Basic runtime and utility functions
*/
@@ -737,9 +753,10 @@ enum {
void fz_new_store_context(fz_context *ctx, unsigned int max);
void fz_free_store_context(fz_context *ctx);
+fz_store *fz_store_keep(fz_context *ctx);
void fz_debug_store(fz_context *ctx);
-void *fz_keep_storable(fz_storable *);
+void *fz_keep_storable(fz_context *, fz_storable *);
void fz_drop_storable(fz_context *, fz_storable *);
void fz_store_item(fz_context *ctx, fz_obj *key, void *val, unsigned int itemsize);
@@ -921,7 +938,7 @@ fz_pixmap *fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, i
fz_pixmap *fz_new_pixmap_with_rect(fz_context *ctx, fz_colorspace *, fz_bbox bbox);
fz_pixmap *fz_new_pixmap_with_rect_and_data(fz_context *ctx, fz_colorspace *, fz_bbox bbox, unsigned char *samples);
fz_pixmap *fz_new_pixmap(fz_context *ctx, fz_colorspace *, int w, int h);
-fz_pixmap *fz_keep_pixmap(fz_pixmap *pix);
+fz_pixmap *fz_keep_pixmap(fz_context *ctx, fz_pixmap *pix);
void fz_drop_pixmap(fz_context *ctx, fz_pixmap *pix);
void fz_free_pixmap_imp(fz_context *ctx, fz_storable *pix);
void fz_clear_pixmap(fz_pixmap *pix);
@@ -1009,7 +1026,7 @@ struct fz_colorspace_s
};
fz_colorspace *fz_new_colorspace(fz_context *ctx, char *name, int n);
-fz_colorspace *fz_keep_colorspace(fz_colorspace *colorspace);
+fz_colorspace *fz_keep_colorspace(fz_context *ctx, fz_colorspace *colorspace);
void fz_drop_colorspace(fz_context *ctx, fz_colorspace *colorspace);
void fz_free_colorspace_imp(fz_context *ctx, fz_storable *colorspace);
@@ -1250,7 +1267,7 @@ struct fz_shade_s
float *mesh; /* [x y 0], [x y r], [x y t] or [x y c1 ... cn] */
};
-fz_shade *fz_keep_shade(fz_shade *shade);
+fz_shade *fz_keep_shade(fz_context *ctx, fz_shade *shade);
void fz_drop_shade(fz_context *ctx, fz_shade *shade);
void fz_free_shade_imp(fz_context *ctx, fz_storable *shade);
void fz_debug_shade(fz_shade *shade);