File: gomaxprocs.go

package info (click to toggle)
golang-github-juju-utils 0.0~git20171220.f38c0b0-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,748 kB
  • sloc: makefile: 20
file content (27 lines) | stat: -rw-r--r-- 666 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
// +build ignore

package utils

import (
	"os"
	"runtime"
)

var gomaxprocs = runtime.GOMAXPROCS
var numCPU = runtime.NumCPU

// UseMultipleCPUs sets GOMAXPROCS to the number of CPU cores unless it has
// already been overridden by the GOMAXPROCS environment variable.
func UseMultipleCPUs() {
	if envGOMAXPROCS := os.Getenv("GOMAXPROCS"); envGOMAXPROCS != "" {
		n := gomaxprocs(0)
		logger.Debugf("GOMAXPROCS already set in environment to %q, %d internally",
			envGOMAXPROCS, n)
		return
	}
	n := numCPU()
	logger.Debugf("setting GOMAXPROCS to %d", n)
	gomaxprocs(n)
}