Skip to content

Commit

Permalink
Use std::once for vips_init call
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Oct 6, 2023
1 parent 58e3c4c commit 08108f5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/sharp.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2013 Lovell Fuller and others.
// SPDX-License-Identifier: Apache-2.0

#include <mutex> // NOLINT(build/c++11)

#include <napi.h>
#include <vips/vips8>

Expand All @@ -10,14 +12,11 @@
#include "utilities.h"
#include "stats.h"

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);
static std::once_flag sharp_vips_init_once;
std::call_once(sharp_vips_init_once, []() {
vips_init("sharp");
});

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

0 comments on commit 08108f5

Please sign in to comment.