-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove PriorityMutex implementation
This is just a code refactor, removing unnecessary extra code. As part of #11859 and #5022 I noticed that PriorityMutex is not useful and can just be replaced by PrioritySemaphore. The only code path that is optimised vs PrioritySempahore is resize which will [never be called](https://github.com/argoproj/argo-workflows/blob/c59ff53a37a7e7ac41f73b23e621f601eab9d604/workflow/sync/sync_manager.go#L340). Otherwise we're performing double sync.Mutex locking for every call because all the implementation of PriorityMutex just calls the relevant method from PrioritySemaphore with it's own lock held, which is wasteful. Signed-off-by: Alan Clucas <[email protected]>
- Loading branch information
Showing
2 changed files
with
13 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,6 @@ | ||
package sync | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
) | ||
|
||
type PriorityMutex struct { | ||
name string | ||
mutex *PrioritySemaphore | ||
lock *sync.Mutex | ||
} | ||
|
||
func (m *PriorityMutex) getCurrentPending() []string { | ||
return m.mutex.getCurrentPending() | ||
} | ||
|
||
var _ Semaphore = &PriorityMutex{} | ||
|
||
// NewMutex creates new mutex lock object | ||
// name of the mutex | ||
// callbackFunc is a release notification function. | ||
func NewMutex(name string, nextWorkflow NextWorkflow) *PriorityMutex { | ||
return &PriorityMutex{ | ||
name: name, | ||
lock: &sync.Mutex{}, | ||
mutex: NewSemaphore(name, 1, nextWorkflow, "mutex"), | ||
} | ||
} | ||
|
||
func (m *PriorityMutex) getName() string { | ||
return m.name | ||
} | ||
|
||
func (m *PriorityMutex) getLimit() int { | ||
return m.mutex.limit | ||
} | ||
|
||
func (m *PriorityMutex) getCurrentHolders() []string { | ||
return m.mutex.getCurrentHolders() | ||
} | ||
|
||
func (m *PriorityMutex) resize(n int) bool { | ||
return false | ||
} | ||
|
||
func (m *PriorityMutex) release(key string) bool { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
return m.mutex.release(key) | ||
} | ||
|
||
func (m *PriorityMutex) acquire(holderKey string) bool { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
return m.mutex.acquire(holderKey) | ||
} | ||
|
||
func (m *PriorityMutex) addToQueue(holderKey string, priority int32, creationTime time.Time) { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
m.mutex.addToQueue(holderKey, priority, creationTime) | ||
} | ||
|
||
func (m *PriorityMutex) removeFromQueue(holderKey string) { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
m.mutex.removeFromQueue(holderKey) | ||
} | ||
|
||
func (m *PriorityMutex) tryAcquire(holderKey string) (bool, string) { | ||
m.lock.Lock() | ||
defer m.lock.Unlock() | ||
return m.mutex.tryAcquire(holderKey) | ||
// NewMutex creates a size 1 semaphore | ||
func NewMutex(name string, nextWorkflow NextWorkflow) *PrioritySemaphore { | ||
return NewSemaphore(name, 1, nextWorkflow, "mutex") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters