Skip to content

Commit

Permalink
Ensure libvips is initialised only once #2143
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Mar 29, 2020
1 parent ecd01af commit 6ed1f49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog.md
Expand Up @@ -4,6 +4,11 @@

Requires libvips v8.9.1

### v0.25.3 - TBD

* Ensure libvips is initialised only once, improves worker thread safety.
[#2143](https://github.com/lovell/sharp/issues/2143)

### v0.25.2 - 20th March 2020

* Provide prebuilt binaries for Linux ARM64v8.
Expand Down
8 changes: 7 additions & 1 deletion src/sharp.cc
Expand Up @@ -21,8 +21,14 @@
#include "utilities.h"
#include "stats.h"

Napi::Object init(Napi::Env env, Napi::Object exports) {
static void* sharp_vips_init(void*) {
vips_init("sharp");
return nullptr;
}

Napi::Object init(Napi::Env env, Napi::Object exports) {
static GOnce sharp_vips_init_once = G_ONCE_INIT;
g_once(&sharp_vips_init_once, static_cast<GThreadFunc>(sharp_vips_init), nullptr);

g_log_set_handler("VIPS", static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING),
static_cast<GLogFunc>(sharp::VipsWarningCallback), nullptr);
Expand Down

0 comments on commit 6ed1f49

Please sign in to comment.