Skip to content

Commit

Permalink
Merge pull request #240 from chrox/master
Browse files Browse the repository at this point in the history
link pthread to wrap-mupdf
  • Loading branch information
thotypous committed Oct 21, 2014
2 parents 1c0cf89 + d3789ed commit afd35f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,10 @@ $(OUTPUT_DIR)/libs/libkoreader-cre.so: cre.cpp \

$(OUTPUT_DIR)/libs/libwrap-mupdf.so: wrap-mupdf.c \
$(MUPDF_LIB)
# Bionic's C library comes with its own pthread implementation
# So we need not to load pthread library for Android build
$(CC) -I$(MUPDF_DIR)/include $(DYNLIB_CFLAGS) \
-o $@ $^
-o $@ $^ $(if $(ANDROID),,-lpthread)

# ===========================================================================
# the attachment extraction tool:
Expand Down
29 changes: 5 additions & 24 deletions ffi/mupdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LuaJIT's FFI.

local ffi = require("ffi")
require("ffi/mupdf_h")
require("ffi/pthread_h")

local BlitBuffer = require("ffi/blitbuffer")

Expand Down Expand Up @@ -646,25 +647,6 @@ local function get_k2pdfopt()
return k2pdfopt
end

-- lazily load libpthread
local pthread
local function get_pthread()
if pthread then return pthread end

local util = require("ffi/util")

require("ffi/pthread_h")

if ffi.os == "Windows" then
-- TODO: what to load on Windows?
elseif util.isAndroid() then
-- pthread directives are in the default namespace on Android
return ffi.C
else
return ffi.load("pthread")
end
end

--[[
the following function is a reimplementation of what can be found
in libk2pdfopt/willuslib/bmpmupdf.c
Expand Down Expand Up @@ -764,13 +746,12 @@ function page_mt.__index:reflow(kopt_context)
render_for_kopt(kopt_context.src, self, scale, bounds)

if kopt_context.precache ~= 0 then
local pthread = get_pthread()
local rf_thread = ffi.new("pthread_t[1]")
local attr = ffi.new("pthread_attr_t")
pthread.pthread_attr_init(attr)
pthread.pthread_attr_setdetachstate(attr, pthread.PTHREAD_CREATE_DETACHED)
pthread.pthread_create(rf_thread, attr, k2pdfopt.k2pdfopt_reflow_bmp, ffi.cast("void*", kopt_context))
pthread.pthread_attr_destroy(attr)
M.pthread_attr_init(attr)
M.pthread_attr_setdetachstate(attr, M.PTHREAD_CREATE_DETACHED)
M.pthread_create(rf_thread, attr, k2pdfopt.k2pdfopt_reflow_bmp, ffi.cast("void*", kopt_context))
M.pthread_attr_destroy(attr)
else
k2pdfopt.k2pdfopt_reflow_bmp(kopt_context)
end
Expand Down

0 comments on commit afd35f8

Please sign in to comment.