-
Notifications
You must be signed in to change notification settings - Fork 22
/
mutex_locker.go
46 lines (35 loc) · 952 Bytes
/
mutex_locker.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package locker
import (
"context"
"sync"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
)
type MutexLockerConfig struct {
Logger micrologger.Logger
}
// MutexLocker implements Interface using sync.Mutex. For now we use a shared
// instance of *MutexLocker for all IPAM related activity of network packages in
// the legacy controllers and ipam resources in the clusterapi controllers.
type MutexLocker struct {
logger micrologger.Logger
mutex sync.Mutex
}
func NewMutexLocker(config MutexLockerConfig) (*MutexLocker, error) {
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
l := &MutexLocker{
logger: config.Logger,
mutex: sync.Mutex{},
}
return l, nil
}
func (l *MutexLocker) Lock(ctx context.Context) error {
l.mutex.Lock()
return nil
}
func (l *MutexLocker) Unlock(ctx context.Context) error {
l.mutex.Unlock()
return nil
}