From 8ac3a08bf217fb527ff875eacdc58b92c95c04bd Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 11:41:45 +0100 Subject: [PATCH] ax(mining): rename ProfileManager.mu to mutex for AX Principle 1 compliance Short name `mu` requires knowledge of Go convention to decode; `mutex` is unambiguous and self-describing per predictable-names-over-short-names. Co-Authored-By: Charon --- pkg/mining/profile_manager.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/mining/profile_manager.go b/pkg/mining/profile_manager.go index 41c167d..5349e4b 100644 --- a/pkg/mining/profile_manager.go +++ b/pkg/mining/profile_manager.go @@ -16,7 +16,7 @@ const profileConfigFileName = "mining_profiles.json" // pm, err := NewProfileManager() // pm.CreateProfile(profile) type ProfileManager struct { - mu sync.RWMutex + mutex sync.RWMutex profiles map[string]*MiningProfile configPath string } @@ -44,10 +44,10 @@ func NewProfileManager() (*ProfileManager, error) { return pm, nil } -// pm.loadProfiles() // call after acquiring pm.mu.Lock() if needed externally +// pm.loadProfiles() // call after acquiring pm.mutex.Lock() if needed externally func (pm *ProfileManager) loadProfiles() error { - pm.mu.Lock() - defer pm.mu.Unlock() + pm.mutex.Lock() + defer pm.mutex.Unlock() data, err := os.ReadFile(pm.configPath) if err != nil { @@ -67,7 +67,7 @@ func (pm *ProfileManager) loadProfiles() error { return nil } -// pm.saveProfiles() // caller must hold pm.mu before calling; uses atomic write (temp→sync→rename) +// pm.saveProfiles() // caller must hold pm.mutex before calling; uses atomic write (temp→sync→rename) func (pm *ProfileManager) saveProfiles() error { profileList := make([]*MiningProfile, 0, len(pm.profiles)) for _, profile := range pm.profiles { @@ -84,8 +84,8 @@ func (pm *ProfileManager) saveProfiles() error { // created, err := pm.CreateProfile(&MiningProfile{Name: "XMRig CPU", MinerType: "xmrig"}) func (pm *ProfileManager) CreateProfile(profile *MiningProfile) (*MiningProfile, error) { - pm.mu.Lock() - defer pm.mu.Unlock() + pm.mutex.Lock() + defer pm.mutex.Unlock() profile.ID = uuid.New().String() pm.profiles[profile.ID] = profile @@ -102,8 +102,8 @@ func (pm *ProfileManager) CreateProfile(profile *MiningProfile) (*MiningProfile, // profile, ok := pm.GetProfile("abc-123") // if !ok { return errors.New("profile not found") } func (pm *ProfileManager) GetProfile(id string) (*MiningProfile, bool) { - pm.mu.RLock() - defer pm.mu.RUnlock() + pm.mutex.RLock() + defer pm.mutex.RUnlock() profile, exists := pm.profiles[id] return profile, exists } @@ -111,8 +111,8 @@ func (pm *ProfileManager) GetProfile(id string) (*MiningProfile, bool) { // profiles := pm.GetAllProfiles() // for _, p := range profiles { render(p) } func (pm *ProfileManager) GetAllProfiles() []*MiningProfile { - pm.mu.RLock() - defer pm.mu.RUnlock() + pm.mutex.RLock() + defer pm.mutex.RUnlock() profileList := make([]*MiningProfile, 0, len(pm.profiles)) for _, profile := range pm.profiles { @@ -124,8 +124,8 @@ func (pm *ProfileManager) GetAllProfiles() []*MiningProfile { // profile.Name = "XMRig GPU" // if err := pm.UpdateProfile(profile); err != nil { return err } func (pm *ProfileManager) UpdateProfile(profile *MiningProfile) error { - pm.mu.Lock() - defer pm.mu.Unlock() + pm.mutex.Lock() + defer pm.mutex.Unlock() oldProfile, exists := pm.profiles[profile.ID] if !exists { @@ -147,8 +147,8 @@ func (pm *ProfileManager) UpdateProfile(profile *MiningProfile) error { // if err := pm.DeleteProfile("abc-123"); err != nil { return err } func (pm *ProfileManager) DeleteProfile(id string) error { - pm.mu.Lock() - defer pm.mu.Unlock() + pm.mutex.Lock() + defer pm.mutex.Unlock() profile, exists := pm.profiles[id] if !exists {