TryAcquire attempts to acquire the connection for use. This is an optimized inline method for the hot path (Get operation). It tries to transition from IDLE -> IN_USE or CREATED -> CREATED. Returns true if the connection was successfully acquired, false otherwise. The CREATED->CREATED is done so we
()
| 808 | // waiter notification, and benchmarks show 1-3% improvement. If the state machine ever |
| 809 | // needs to notify waiters on these transitions, update this to use TryTransitionFast(). |
| 810 | func (cn *Conn) TryAcquire() bool { |
| 811 | // The || operator short-circuits, so only 1 CAS in the common case |
| 812 | return cn.stateMachine.state.CompareAndSwap(uint32(StateIdle), uint32(StateInUse)) || |
| 813 | cn.stateMachine.state.CompareAndSwap(uint32(StateCreated), uint32(StateCreated)) |
| 814 | } |
| 815 | |
| 816 | // Release releases the connection back to the pool. |
| 817 | // This is an optimized inline method for the hot path (Put operation). |
no outgoing calls
no test coverage detected