Improve thread/buffer shutdown using new vips_thread_shutdown method - closes #5

This commit is contained in:
Lovell Fuller 2014-01-15 21:35:44 +00:00
parent f7b8ce1287
commit 7e8af63129
3 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sharp", "name": "sharp",
"version": "0.0.7", "version": "0.0.8",
"author": "Lovell Fuller", "author": "Lovell Fuller",
"description": "High performance module to resize JPEG and PNG images using the libvips image processing library", "description": "High performance module to resize JPEG and PNG images using the libvips image processing library",
"scripts": { "scripts": {

View File

@ -160,6 +160,7 @@ void ResizeAsync(uv_work_t *work) {
} else { } else {
(baton->err).append("Unsupported output file type"); (baton->err).append("Unsupported output file type");
} }
vips_thread_shutdown();
} }
void ResizeAsyncAfter(uv_work_t *work, int status) { void ResizeAsyncAfter(uv_work_t *work, int status) {
@ -176,6 +177,7 @@ void ResizeAsyncAfter(uv_work_t *work, int status) {
// Buffer // Buffer
Buffer *buffer = Buffer::New((const char*)(baton->buffer_out), baton->buffer_out_len); Buffer *buffer = Buffer::New((const char*)(baton->buffer_out), baton->buffer_out_len);
argv[1] = Local<Object>::New(buffer->handle_); argv[1] = Local<Object>::New(buffer->handle_);
vips_free(baton->buffer_out);
} }
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
@ -210,9 +212,15 @@ Handle<Value> Resize(const Arguments& args) {
return Undefined(); return Undefined();
} }
static void at_exit(void* arg) {
HandleScope scope;
vips_shutdown();
}
extern "C" void init(Handle<Object> target) { extern "C" void init(Handle<Object> target) {
HandleScope scope; HandleScope scope;
vips_init(""); vips_init("");
AtExit(at_exit);
NODE_SET_METHOD(target, "resize", Resize); NODE_SET_METHOD(target, "resize", Resize);
}; };

View File

@ -12,7 +12,7 @@ var outputJpgLength = 47035;
var inputPng = __dirname + "/50020484-00001.png"; // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png var inputPng = __dirname + "/50020484-00001.png"; // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
var outputPng = __dirname + "/output.png"; var outputPng = __dirname + "/output.png";
var outputPngLength = 60379; var outputPngLength = 60380;
var width = 640; var width = 640;
var height = 480; var height = 480;