2015-04-22 22:54:31 +00:00
|
|
|
// Copyright (C) 2015 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-04-22 22:54:31 +00:00
|
|
|
|
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2019-02-02 10:45:17 +00:00
|
|
|
deadlock "github.com/sasha-s/go-deadlock"
|
2016-11-05 02:31:52 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/logger"
|
2015-04-22 22:54:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-12-17 14:37:11 +00:00
|
|
|
threshold = 100 * time.Millisecond
|
2015-10-03 15:25:21 +00:00
|
|
|
l = logger.DefaultLogger.NewFacility("sync", "Mutexes")
|
|
|
|
|
|
|
|
// We make an exception in this package and have an actual "if debug { ...
|
|
|
|
// }" variable, as it may be rather performance critical and does
|
|
|
|
// nonstandard things (from a debug logging PoV).
|
2019-10-04 11:03:34 +00:00
|
|
|
debug = logger.DefaultLogger.ShouldDebug("sync")
|
2018-01-15 13:33:52 +00:00
|
|
|
useDeadlock = false
|
2015-04-22 22:54:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-01-15 13:33:52 +00:00
|
|
|
if n, _ := strconv.Atoi(os.Getenv("STLOCKTHRESHOLD")); n > 0 {
|
2016-11-05 02:31:52 +00:00
|
|
|
threshold = time.Duration(n) * time.Millisecond
|
|
|
|
}
|
2018-01-15 13:33:52 +00:00
|
|
|
l.Debugf("Enabling lock logging at %v threshold", threshold)
|
|
|
|
|
|
|
|
if n, _ := strconv.Atoi(os.Getenv("STDEADLOCKTIMEOUT")); n > 0 {
|
2016-11-05 02:31:52 +00:00
|
|
|
deadlock.Opts.DeadlockTimeout = time.Duration(n) * time.Second
|
2018-01-15 13:33:52 +00:00
|
|
|
l.Debugf("Enabling lock deadlocking at %v", deadlock.Opts.DeadlockTimeout)
|
|
|
|
useDeadlock = true
|
2015-04-22 22:54:31 +00:00
|
|
|
}
|
2015-10-03 15:25:21 +00:00
|
|
|
}
|