(c *Config)
| 49 | } |
| 50 | |
| 51 | func Init(c *Config) error { |
| 52 | if err := c.Validate(); err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | config = c |
| 57 | |
| 58 | runtime.LockOSThread() |
| 59 | defer runtime.UnlockOSThread() |
| 60 | |
| 61 | // vips_initialize must be called only once |
| 62 | var initErr error |
| 63 | initOnce.Do(func() { |
| 64 | if err := C.vips_initialize(); err != 0 { |
| 65 | C.vips_shutdown() |
| 66 | initErr = newVipsError("unable to start vips!") |
| 67 | } |
| 68 | }) |
| 69 | if initErr != nil { |
| 70 | return initErr |
| 71 | } |
| 72 | |
| 73 | // Disable libvips cache. Since processing pipeline is fine tuned, we won't get much profit from it. |
| 74 | // Enabled cache can cause SIGSEGV on Musl-based systems like Alpine. |
| 75 | C.vips_cache_set_max_mem(0) |
| 76 | C.vips_cache_set_max(0) |
| 77 | |
| 78 | if lambdaFn := os.Getenv("AWS_LAMBDA_FUNCTION_NAME"); len(lambdaFn) > 0 { |
| 79 | // Set vips concurrency level to GOMAXPROCS if we are running in AWS Lambda |
| 80 | // since each function processes only one request at a time |
| 81 | // so we can use all available CPU cores |
| 82 | C.vips_concurrency_set(C.int(max(1, runtime.GOMAXPROCS(0)))) |
| 83 | } else { |
| 84 | C.vips_concurrency_set(1) |
| 85 | } |
| 86 | |
| 87 | C.vips_leak_set(gbool(config.LeakCheck)) |
| 88 | C.vips_cache_set_trace(gbool(config.CacheTrace)) |
| 89 | |
| 90 | gifResolutionLimit = int(C.gif_resolution_limit()) |
| 91 | |
| 92 | return nil |
| 93 | } |
| 94 | |
| 95 | func Shutdown() { |
| 96 | C.vips_shutdown() |
no test coverage detected