Selaa lähdekoodia

use embedded lock

Sean Holcomb 4 vuotta sitten
vanhempi
sitoutus
79cb73afea
1 muutettua tiedostoa jossa 5 lisäystä ja 6 poistoa
  1. 5 6
      pkg/cloud/provider.go

+ 5 - 6
pkg/cloud/provider.go

@@ -215,28 +215,27 @@ type ServiceAccountStatus struct {
 
 // ServiceAccountChecks is a thread safe map for holding ServiceAccountCheck objects
 type ServiceAccountChecks struct {
+	sync.RWMutex
 	serviceAccountChecks map[string]*ServiceAccountCheck
-	lock                 *sync.RWMutex
 }
 
 // NewServiceAccountChecks initialize ServiceAccountChecks
 func NewServiceAccountChecks() *ServiceAccountChecks {
 	return &ServiceAccountChecks{
 		serviceAccountChecks: make(map[string]*ServiceAccountCheck),
-		lock: new(sync.RWMutex),
 	}
 }
 
 func (sac *ServiceAccountChecks) set(key string, check *ServiceAccountCheck) {
-	sac.lock.Lock()
-	defer sac.lock.Unlock()
+	sac.Lock()
+	defer sac.Unlock()
 	sac.serviceAccountChecks[key] = check
 }
 
 // getStatus extracts ServiceAccountCheck objects into a slice and returns them in a ServiceAccountStatus
 func (sac *ServiceAccountChecks) getStatus() *ServiceAccountStatus {
-	sac.lock.Lock()
-	defer sac.lock.Unlock()
+	sac.Lock()
+	defer sac.Unlock()
 	checks := []*ServiceAccountCheck{}
 	for _, v := range sac.serviceAccountChecks {
 		checks = append(checks, v)