mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
* New condition variable which can be interrupted & UT * New priority mutex & UT Below shows the new priority mutex compared to existing implementation: BenchmarkPriorityMutex_High & BenchmarkPriorityMutex_Low are from new implementation BenchmarkLock is existing implementation ```bash goos: darwin goarch: amd64 pkg: go.temporal.io/server/common/locks cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkPriorityMutex_High BenchmarkPriorityMutex_High-16 32627506 34.08 ns/op 0 B/op 0 allocs/op PASS goos: darwin goarch: amd64 pkg: go.temporal.io/server/common/locks cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkPriorityMutex_Low BenchmarkPriorityMutex_Low-16 33031749 33.32 ns/op 0 B/op 0 allocs/op PASS goos: darwin goarch: amd64 pkg: go.temporal.io/server/common/locks cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz BenchmarkLock BenchmarkLock-16 1985761 557.3 ns/op 100 B/op 2 allocs/op PASS ```
40 lines
1.8 KiB
Go
40 lines
1.8 KiB
Go
// The MIT License
|
|
//
|
|
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
|
|
//
|
|
// Copyright (c) 2020 Uber Technologies, Inc.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
package locks
|
|
|
|
type (
|
|
// ConditionVariable is the interface for condition variable
|
|
ConditionVariable interface {
|
|
// Signal wakes one goroutine waiting on this condition variable, if there is any.
|
|
Signal()
|
|
// Broadcast wakes all goroutines waiting on this condition variable.
|
|
Broadcast()
|
|
// Wait atomically unlocks user provided lock and suspends execution of the calling goroutine.
|
|
// After later resuming execution, Wait locks c.L before returning.
|
|
// Wait can be awoken by Broadcast, Signal or user provided interrupt channel.
|
|
Wait(interrupt <-chan struct{})
|
|
}
|
|
)
|