mirror of
https://github.com/redis/go-redis.git
synced 2025-12-02 06:22:31 +03:00
address linter and tests
This commit is contained in:
@@ -218,6 +218,8 @@ func (sm *ConnStateMachine) AwaitAndTransition(
|
|||||||
targetState ConnState,
|
targetState ConnState,
|
||||||
) (ConnState, error) {
|
) (ConnState, error) {
|
||||||
// Fast path: try immediate transition with CAS to prevent race conditions
|
// Fast path: try immediate transition with CAS to prevent race conditions
|
||||||
|
// BUT: only if there are no waiters in the queue (to maintain FIFO ordering)
|
||||||
|
if sm.waiterCount.Load() == 0 {
|
||||||
for _, fromState := range validFromStates {
|
for _, fromState := range validFromStates {
|
||||||
// Check if we're already in target state
|
// Check if we're already in target state
|
||||||
if fromState == targetState && sm.GetState() == targetState {
|
if fromState == targetState && sm.GetState() == targetState {
|
||||||
@@ -231,6 +233,7 @@ func (sm *ConnStateMachine) AwaitAndTransition(
|
|||||||
return targetState, nil
|
return targetState, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fast path failed - check if we should wait or fail
|
// Fast path failed - check if we should wait or fail
|
||||||
currentState := sm.GetState()
|
currentState := sm.GetState()
|
||||||
|
|||||||
@@ -14,12 +14,6 @@ var semTimers = sync.Pool{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// waiter represents a goroutine waiting for a token.
|
|
||||||
type waiter struct {
|
|
||||||
ready chan struct{}
|
|
||||||
next *waiter
|
|
||||||
}
|
|
||||||
|
|
||||||
// FastSemaphore is a channel-based semaphore optimized for performance.
|
// FastSemaphore is a channel-based semaphore optimized for performance.
|
||||||
// It uses a fast path that avoids timer allocation when tokens are available.
|
// It uses a fast path that avoids timer allocation when tokens are available.
|
||||||
// The channel is pre-filled with tokens: Acquire = receive, Release = send.
|
// The channel is pre-filled with tokens: Acquire = receive, Release = send.
|
||||||
|
|||||||
Reference in New Issue
Block a user