mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 00:42:49 +08:00
Some checks are pending
Test / test (1.20, macos-13) (push) Waiting to run
Test / test (1.20, macos-latest) (push) Waiting to run
Test / test (1.20, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.20, ubuntu-latest) (push) Waiting to run
Test / test (1.20, windows-latest) (push) Waiting to run
Test / test (1.21, macos-13) (push) Waiting to run
Test / test (1.21, macos-latest) (push) Waiting to run
Test / test (1.21, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.21, ubuntu-latest) (push) Waiting to run
Test / test (1.21, windows-latest) (push) Waiting to run
Test / test (1.22, macos-13) (push) Waiting to run
Test / test (1.22, macos-latest) (push) Waiting to run
Test / test (1.22, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.22, ubuntu-latest) (push) Waiting to run
Test / test (1.22, windows-latest) (push) Waiting to run
Test / test (1.23, macos-13) (push) Waiting to run
Test / test (1.23, macos-latest) (push) Waiting to run
Test / test (1.23, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.23, ubuntu-latest) (push) Waiting to run
Test / test (1.23, windows-latest) (push) Waiting to run
Test / test (1.24, macos-13) (push) Waiting to run
Test / test (1.24, macos-latest) (push) Waiting to run
Test / test (1.24, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.24, ubuntu-latest) (push) Waiting to run
Test / test (1.24, windows-latest) (push) Waiting to run
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
29 lines
1006 B
Go
29 lines
1006 B
Go
package xsync
|
|
|
|
// LoadOrStoreFn returns the existing value for the key if
|
|
// present. Otherwise, it tries to compute the value using the
|
|
// provided function and, if successful, stores and returns
|
|
// the computed value. The loaded result is true if the value was
|
|
// loaded, or false if computed.
|
|
//
|
|
// This call locks a hash table bucket while the compute function
|
|
// is executed. It means that modifications on other entries in
|
|
// the bucket will be blocked until the valueFn executes. Consider
|
|
// this when the function includes long-running operations.
|
|
//
|
|
// Recovery this API and renamed from xsync/v3's LoadOrCompute.
|
|
// We unneeded support no-op (cancel) compute operation, it will only add complexity to existing code.
|
|
func (m *Map[K, V]) LoadOrStoreFn(key K, valueFn func() V) (actual V, loaded bool) {
|
|
return m.doCompute(
|
|
key,
|
|
func(oldValue V, loaded bool) (V, ComputeOp) {
|
|
if loaded {
|
|
return oldValue, CancelOp
|
|
}
|
|
return valueFn(), UpdateOp
|
|
},
|
|
loadOrComputeOp,
|
|
false,
|
|
)
|
|
}
|