9
9
"github.com/Sirupsen/logrus"
10
10
)
11
11
12
- // Mutex is debug mutex, which prints logs and traces for locks
13
- // implements sync.Locker interface
12
+ // Mutex is debugging mutex, which prints logs and traces for locks.
13
+ // Mutex implements sync.Locker interface.
14
14
type Mutex struct {
15
15
retries int
16
16
mu sync.Mutex
@@ -19,10 +19,10 @@ type Mutex struct {
19
19
errFunc func (format string , args ... interface {})
20
20
}
21
21
22
- // New returns new debug mutex
23
- // retries parameter specify number of retries acquiring Mutex before error
24
- // message, if <=0, then wait forever
25
- // if fatal is true, then program will exit by os.Exit(1)
22
+ // New returns new debug mutex.
23
+ // retries specify the number of retries acquiring Mutex before error
24
+ // message, if <=0, then retry forever.
25
+ // If fatal is true, then program will exit by os.Exit(1).
26
26
func New (retries int , fatal bool ) sync.Locker {
27
27
var errF func (format string , args ... interface {})
28
28
errF = logrus .Errorf
@@ -36,8 +36,8 @@ func New(retries int, fatal bool) sync.Locker {
36
36
}
37
37
38
38
// Lock tries to lock mutex. Interval between attempts is 1 second.
39
- // On each attempt stack trace and file:lino of previous Lock will be printed.
40
- // Lock does os.Exit(1) after last attempt.
39
+ // On each attempt stack trace and file:line of a previous Lock printed.
40
+ // Lock does os.Exit(1) after last attempt if fatal parameter was true .
41
41
func (m * Mutex ) Lock () {
42
42
_ , file , line , _ := runtime .Caller (1 )
43
43
caller := fmt .Sprintf ("%s:%d" , file , line )
71
71
m .myMu .Unlock ()
72
72
}
73
73
74
- // Unlock unlocks mutex. It prints place in code where it was called and where
75
- // mutex was locked.
74
+ // Unlock unlocks the mutex. It prints place in the code where it was called
75
+ // and where mutex was locked.
76
76
func (m * Mutex ) Unlock () {
77
77
_ , file , line , _ := runtime .Caller (1 )
78
78
caller := fmt .Sprintf ("%s:%d" , file , line )
0 commit comments