From 40f4ed22806b88ba0e26c458915d4695f1f7c201 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 18 Jan 2012 15:49:09 +0000 Subject: 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. --- fitz/base_memory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'fitz/base_memory.c') diff --git a/fitz/base_memory.c b/fitz/base_memory.c index 0b043a32..c9b94f1e 100644 --- a/fitz/base_memory.c +++ b/fitz/base_memory.c @@ -6,13 +6,13 @@ do_scavenging_malloc(fz_context *ctx, unsigned int size) void *p; int phase = 0; - /* LOCK */ + fz_lock(ctx); do { p = ctx->alloc->malloc(ctx->alloc->user, size); if (p != NULL) return p; } while (fz_store_scavenge(ctx, size, &phase)); - /* UNLOCK */ + fz_unlock(ctx); return NULL; } @@ -23,13 +23,13 @@ do_scavenging_realloc(fz_context *ctx, void *p, unsigned int size) void *q; int phase = 0; - /* LOCK */ + fz_lock(ctx); do { q = ctx->alloc->realloc(ctx->alloc->user, p, size); if (q != NULL) return q; } while (fz_store_scavenge(ctx, size, &phase)); - /* UNLOCK */ + fz_unlock(ctx); return NULL; } @@ -171,9 +171,9 @@ fz_resize_array_no_throw(fz_context *ctx, void *p, unsigned int count, unsigned void fz_free(fz_context *ctx, void *p) { - /* LOCK */ + fz_lock(ctx); ctx->alloc->free(ctx->alloc->user, p); - /* UNLOCK */ + fz_unlock(ctx); } char * -- cgit v1.2.3