|
@@ -24,13 +24,11 @@ import ( |
|
@@ -24,13 +24,11 @@ import ( |
|
24
|
"sync"
|
24
|
"sync"
|
|
25
|
"sync/atomic"
|
25
|
"sync/atomic"
|
|
26
|
"time"
|
26
|
"time"
|
|
27
|
-
|
|
|
|
28
|
- "github.com/garyburd/redigo/internal"
|
|
|
|
29
|
)
|
27
|
)
|
|
30
|
|
28
|
|
|
31
|
var (
|
29
|
var (
|
|
32
|
- _ ConnWithTimeout = (*pooledConnection)(nil)
|
|
|
|
33
|
- _ ConnWithTimeout = (*errorConnection)(nil)
|
30
|
+ _ ConnWithTimeout = (*activeConn)(nil)
|
|
|
|
31
|
+ _ ConnWithTimeout = (*errorConn)(nil)
|
|
34
|
)
|
32
|
)
|
|
35
|
|
33
|
|
|
36
|
var nowFunc = time.Now // for testing
|
34
|
var nowFunc = time.Now // for testing
|
|
@@ -150,6 +148,10 @@ type Pool struct { |
|
@@ -150,6 +148,10 @@ type Pool struct { |
|
150
|
// for a connection to be returned to the pool before returning.
|
148
|
// for a connection to be returned to the pool before returning.
|
|
151
|
Wait bool
|
149
|
Wait bool
|
|
152
|
|
150
|
|
|
|
|
151
|
+ // Close connections older than this duration. If the value is zero, then
|
|
|
|
152
|
+ // the pool does not close connections based on age.
|
|
|
|
153
|
+ MaxConnLifetime time.Duration
|
|
|
|
154
|
+
|
|
153
|
chInitialized uint32 // set to 1 when field ch is initialized
|
155
|
chInitialized uint32 // set to 1 when field ch is initialized
|
|
154
|
|
156
|
|
|
155
|
mu sync.Mutex // mu protects the following fields
|
157
|
mu sync.Mutex // mu protects the following fields
|
|
@@ -172,11 +174,11 @@ func NewPool(newFn func() (Conn, error), maxIdle int) *Pool { |
|
@@ -172,11 +174,11 @@ func NewPool(newFn func() (Conn, error), maxIdle int) *Pool { |
|
172
|
// getting an underlying connection, then the connection Err, Do, Send, Flush
|
174
|
// getting an underlying connection, then the connection Err, Do, Send, Flush
|
|
173
|
// and Receive methods return that error.
|
175
|
// and Receive methods return that error.
|
|
174
|
func (p *Pool) Get() Conn {
|
176
|
func (p *Pool) Get() Conn {
|
|
175
|
- c, err := p.get(nil)
|
177
|
+ pc, err := p.get(nil)
|
|
176
|
if err != nil {
|
178
|
if err != nil {
|
|
177
|
- return errorConnection{err}
|
179
|
+ return errorConn{err}
|
|
178
|
}
|
180
|
}
|
|
179
|
- return &pooledConnection{p: p, c: c}
|
181
|
+ return &activeConn{p: p, pc: pc}
|
|
180
|
}
|
182
|
}
|
|
181
|
|
183
|
|
|
182
|
// PoolStats contains pool statistics.
|
184
|
// PoolStats contains pool statistics.
|
|
@@ -226,15 +228,15 @@ func (p *Pool) Close() error { |
|
@@ -226,15 +228,15 @@ func (p *Pool) Close() error { |
|
226
|
}
|
228
|
}
|
|
227
|
p.closed = true
|
229
|
p.closed = true
|
|
228
|
p.active -= p.idle.count
|
230
|
p.active -= p.idle.count
|
|
229
|
- ic := p.idle.front
|
231
|
+ pc := p.idle.front
|
|
230
|
p.idle.count = 0
|
232
|
p.idle.count = 0
|
|
231
|
p.idle.front, p.idle.back = nil, nil
|
233
|
p.idle.front, p.idle.back = nil, nil
|
|
232
|
if p.ch != nil {
|
234
|
if p.ch != nil {
|
|
233
|
close(p.ch)
|
235
|
close(p.ch)
|
|
234
|
}
|
236
|
}
|
|
235
|
p.mu.Unlock()
|
237
|
p.mu.Unlock()
|
|
236
|
- for ; ic != nil; ic = ic.next {
|
|
|
|
237
|
- ic.c.Close()
|
238
|
+ for ; pc != nil; pc = pc.next {
|
|
|
|
239
|
+ pc.c.Close()
|
|
238
|
}
|
240
|
}
|
|
239
|
return nil
|
241
|
return nil
|
|
240
|
}
|
242
|
}
|
|
@@ -265,7 +267,7 @@ func (p *Pool) lazyInit() { |
|
@@ -265,7 +267,7 @@ func (p *Pool) lazyInit() { |
|
265
|
func (p *Pool) get(ctx interface {
|
267
|
func (p *Pool) get(ctx interface {
|
|
266
|
Done() <-chan struct{}
|
268
|
Done() <-chan struct{}
|
|
267
|
Err() error
|
269
|
Err() error
|
|
268
|
-}) (Conn, error) {
|
270
|
+}) (*poolConn, error) {
|
|
269
|
|
271
|
|
|
270
|
// Handle limit for p.Wait == true.
|
272
|
// Handle limit for p.Wait == true.
|
|
271
|
if p.Wait && p.MaxActive > 0 {
|
273
|
if p.Wait && p.MaxActive > 0 {
|
|
@@ -287,10 +289,10 @@ func (p *Pool) get(ctx interface { |
|
@@ -287,10 +289,10 @@ func (p *Pool) get(ctx interface { |
|
287
|
if p.IdleTimeout > 0 {
|
289
|
if p.IdleTimeout > 0 {
|
|
288
|
n := p.idle.count
|
290
|
n := p.idle.count
|
|
289
|
for i := 0; i < n && p.idle.back != nil && p.idle.back.t.Add(p.IdleTimeout).Before(nowFunc()); i++ {
|
291
|
for i := 0; i < n && p.idle.back != nil && p.idle.back.t.Add(p.IdleTimeout).Before(nowFunc()); i++ {
|
|
290
|
- c := p.idle.back.c
|
292
|
+ pc := p.idle.back
|
|
291
|
p.idle.popBack()
|
293
|
p.idle.popBack()
|
|
292
|
p.mu.Unlock()
|
294
|
p.mu.Unlock()
|
|
293
|
- c.Close()
|
295
|
+ pc.c.Close()
|
|
294
|
p.mu.Lock()
|
296
|
p.mu.Lock()
|
|
295
|
p.active--
|
297
|
p.active--
|
|
296
|
}
|
298
|
}
|
|
@@ -298,13 +300,14 @@ func (p *Pool) get(ctx interface { |
|
@@ -298,13 +300,14 @@ func (p *Pool) get(ctx interface { |
|
298
|
|
300
|
|
|
299
|
// Get idle connection from the front of idle list.
|
301
|
// Get idle connection from the front of idle list.
|
|
300
|
for p.idle.front != nil {
|
302
|
for p.idle.front != nil {
|
|
301
|
- ic := p.idle.front
|
303
|
+ pc := p.idle.front
|
|
302
|
p.idle.popFront()
|
304
|
p.idle.popFront()
|
|
303
|
p.mu.Unlock()
|
305
|
p.mu.Unlock()
|
|
304
|
- if p.TestOnBorrow == nil || p.TestOnBorrow(ic.c, ic.t) == nil {
|
|
|
|
305
|
- return ic.c, nil
|
306
|
+ if (p.TestOnBorrow == nil || p.TestOnBorrow(pc.c, pc.t) == nil) &&
|
|
|
|
307
|
+ (p.MaxConnLifetime == 0 || nowFunc().Sub(pc.created) < p.MaxConnLifetime) {
|
|
|
|
308
|
+ return pc, nil
|
|
306
|
}
|
309
|
}
|
|
307
|
- ic.c.Close()
|
310
|
+ pc.c.Close()
|
|
308
|
p.mu.Lock()
|
311
|
p.mu.Lock()
|
|
309
|
p.active--
|
312
|
p.active--
|
|
310
|
}
|
313
|
}
|
|
@@ -333,24 +336,25 @@ func (p *Pool) get(ctx interface { |
|
@@ -333,24 +336,25 @@ func (p *Pool) get(ctx interface { |
|
333
|
}
|
336
|
}
|
|
334
|
p.mu.Unlock()
|
337
|
p.mu.Unlock()
|
|
335
|
}
|
338
|
}
|
|
336
|
- return c, err
|
339
|
+ return &poolConn{c: c, created: nowFunc()}, err
|
|
337
|
}
|
340
|
}
|
|
338
|
|
341
|
|
|
339
|
-func (p *Pool) put(c Conn, forceClose bool) error {
|
342
|
+func (p *Pool) put(pc *poolConn, forceClose bool) error {
|
|
340
|
p.mu.Lock()
|
343
|
p.mu.Lock()
|
|
341
|
if !p.closed && !forceClose {
|
344
|
if !p.closed && !forceClose {
|
|
342
|
- p.idle.pushFront(&idleConn{t: nowFunc(), c: c})
|
345
|
+ pc.t = nowFunc()
|
|
|
|
346
|
+ p.idle.pushFront(pc)
|
|
343
|
if p.idle.count > p.MaxIdle {
|
347
|
if p.idle.count > p.MaxIdle {
|
|
344
|
- c = p.idle.back.c
|
348
|
+ pc = p.idle.back
|
|
345
|
p.idle.popBack()
|
349
|
p.idle.popBack()
|
|
346
|
} else {
|
350
|
} else {
|
|
347
|
- c = nil
|
351
|
+ pc = nil
|
|
348
|
}
|
352
|
}
|
|
349
|
}
|
353
|
}
|
|
350
|
|
354
|
|
|
351
|
- if c != nil {
|
355
|
+ if pc != nil {
|
|
352
|
p.mu.Unlock()
|
356
|
p.mu.Unlock()
|
|
353
|
- c.Close()
|
357
|
+ pc.c.Close()
|
|
354
|
p.mu.Lock()
|
358
|
p.mu.Lock()
|
|
355
|
p.active--
|
359
|
p.active--
|
|
356
|
}
|
360
|
}
|
|
@@ -362,9 +366,9 @@ func (p *Pool) put(c Conn, forceClose bool) error { |
|
@@ -362,9 +366,9 @@ func (p *Pool) put(c Conn, forceClose bool) error { |
|
362
|
return nil
|
366
|
return nil
|
|
363
|
}
|
367
|
}
|
|
364
|
|
368
|
|
|
365
|
-type pooledConnection struct {
|
369
|
+type activeConn struct {
|
|
366
|
p *Pool
|
370
|
p *Pool
|
|
367
|
- c Conn
|
371
|
+ pc *poolConn
|
|
368
|
state int
|
372
|
state int
|
|
369
|
}
|
373
|
}
|
|
370
|
|
374
|
|
|
@@ -385,79 +389,107 @@ func initSentinel() { |
|
@@ -385,79 +389,107 @@ func initSentinel() { |
|
385
|
}
|
389
|
}
|
|
386
|
}
|
390
|
}
|
|
387
|
|
391
|
|
|
388
|
-func (pc *pooledConnection) Close() error {
|
|
|
|
389
|
- c := pc.c
|
|
|
|
390
|
- if _, ok := c.(errorConnection); ok {
|
392
|
+func (ac *activeConn) Close() error {
|
|
|
|
393
|
+ pc := ac.pc
|
|
|
|
394
|
+ if pc == nil {
|
|
391
|
return nil
|
395
|
return nil
|
|
392
|
}
|
396
|
}
|
|
393
|
- pc.c = errorConnection{errConnClosed}
|
397
|
+ ac.pc = nil
|
|
394
|
|
398
|
|
|
395
|
- if pc.state&internal.MultiState != 0 {
|
|
|
|
396
|
- c.Send("DISCARD")
|
|
|
|
397
|
- pc.state &^= (internal.MultiState | internal.WatchState)
|
|
|
|
398
|
- } else if pc.state&internal.WatchState != 0 {
|
|
|
|
399
|
- c.Send("UNWATCH")
|
|
|
|
400
|
- pc.state &^= internal.WatchState
|
399
|
+ if ac.state&connectionMultiState != 0 {
|
|
|
|
400
|
+ pc.c.Send("DISCARD")
|
|
|
|
401
|
+ ac.state &^= (connectionMultiState | connectionWatchState)
|
|
|
|
402
|
+ } else if ac.state&connectionWatchState != 0 {
|
|
|
|
403
|
+ pc.c.Send("UNWATCH")
|
|
|
|
404
|
+ ac.state &^= connectionWatchState
|
|
401
|
}
|
405
|
}
|
|
402
|
- if pc.state&internal.SubscribeState != 0 {
|
|
|
|
403
|
- c.Send("UNSUBSCRIBE")
|
|
|
|
404
|
- c.Send("PUNSUBSCRIBE")
|
406
|
+ if ac.state&connectionSubscribeState != 0 {
|
|
|
|
407
|
+ pc.c.Send("UNSUBSCRIBE")
|
|
|
|
408
|
+ pc.c.Send("PUNSUBSCRIBE")
|
|
405
|
// To detect the end of the message stream, ask the server to echo
|
409
|
// To detect the end of the message stream, ask the server to echo
|
|
406
|
// a sentinel value and read until we see that value.
|
410
|
// a sentinel value and read until we see that value.
|
|
407
|
sentinelOnce.Do(initSentinel)
|
411
|
sentinelOnce.Do(initSentinel)
|
|
408
|
- c.Send("ECHO", sentinel)
|
|
|
|
409
|
- c.Flush()
|
412
|
+ pc.c.Send("ECHO", sentinel)
|
|
|
|
413
|
+ pc.c.Flush()
|
|
410
|
for {
|
414
|
for {
|
|
411
|
- p, err := c.Receive()
|
415
|
+ p, err := pc.c.Receive()
|
|
412
|
if err != nil {
|
416
|
if err != nil {
|
|
413
|
break
|
417
|
break
|
|
414
|
}
|
418
|
}
|
|
415
|
if p, ok := p.([]byte); ok && bytes.Equal(p, sentinel) {
|
419
|
if p, ok := p.([]byte); ok && bytes.Equal(p, sentinel) {
|
|
416
|
- pc.state &^= internal.SubscribeState
|
420
|
+ ac.state &^= connectionSubscribeState
|
|
417
|
break
|
421
|
break
|
|
418
|
}
|
422
|
}
|
|
419
|
}
|
423
|
}
|
|
420
|
}
|
424
|
}
|
|
421
|
- c.Do("")
|
|
|
|
422
|
- pc.p.put(c, pc.state != 0 || c.Err() != nil)
|
425
|
+ pc.c.Do("")
|
|
|
|
426
|
+ ac.p.put(pc, ac.state != 0 || pc.c.Err() != nil)
|
|
423
|
return nil
|
427
|
return nil
|
|
424
|
}
|
428
|
}
|
|
425
|
|
429
|
|
|
426
|
-func (pc *pooledConnection) Err() error {
|
430
|
+func (ac *activeConn) Err() error {
|
|
|
|
431
|
+ pc := ac.pc
|
|
|
|
432
|
+ if pc == nil {
|
|
|
|
433
|
+ return errConnClosed
|
|
|
|
434
|
+ }
|
|
427
|
return pc.c.Err()
|
435
|
return pc.c.Err()
|
|
428
|
}
|
436
|
}
|
|
429
|
|
437
|
|
|
430
|
-func (pc *pooledConnection) Do(commandName string, args ...interface{}) (reply interface{}, err error) {
|
|
|
|
431
|
- ci := internal.LookupCommandInfo(commandName)
|
|
|
|
432
|
- pc.state = (pc.state | ci.Set) &^ ci.Clear
|
438
|
+func (ac *activeConn) Do(commandName string, args ...interface{}) (reply interface{}, err error) {
|
|
|
|
439
|
+ pc := ac.pc
|
|
|
|
440
|
+ if pc == nil {
|
|
|
|
441
|
+ return nil, errConnClosed
|
|
|
|
442
|
+ }
|
|
|
|
443
|
+ ci := lookupCommandInfo(commandName)
|
|
|
|
444
|
+ ac.state = (ac.state | ci.Set) &^ ci.Clear
|
|
433
|
return pc.c.Do(commandName, args...)
|
445
|
return pc.c.Do(commandName, args...)
|
|
434
|
}
|
446
|
}
|
|
435
|
|
447
|
|
|
436
|
-func (pc *pooledConnection) DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (reply interface{}, err error) {
|
448
|
+func (ac *activeConn) DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (reply interface{}, err error) {
|
|
|
|
449
|
+ pc := ac.pc
|
|
|
|
450
|
+ if pc == nil {
|
|
|
|
451
|
+ return nil, errConnClosed
|
|
|
|
452
|
+ }
|
|
437
|
cwt, ok := pc.c.(ConnWithTimeout)
|
453
|
cwt, ok := pc.c.(ConnWithTimeout)
|
|
438
|
if !ok {
|
454
|
if !ok {
|
|
439
|
return nil, errTimeoutNotSupported
|
455
|
return nil, errTimeoutNotSupported
|
|
440
|
}
|
456
|
}
|
|
441
|
- ci := internal.LookupCommandInfo(commandName)
|
|
|
|
442
|
- pc.state = (pc.state | ci.Set) &^ ci.Clear
|
457
|
+ ci := lookupCommandInfo(commandName)
|
|
|
|
458
|
+ ac.state = (ac.state | ci.Set) &^ ci.Clear
|
|
443
|
return cwt.DoWithTimeout(timeout, commandName, args...)
|
459
|
return cwt.DoWithTimeout(timeout, commandName, args...)
|
|
444
|
}
|
460
|
}
|
|
445
|
|
461
|
|
|
446
|
-func (pc *pooledConnection) Send(commandName string, args ...interface{}) error {
|
|
|
|
447
|
- ci := internal.LookupCommandInfo(commandName)
|
|
|
|
448
|
- pc.state = (pc.state | ci.Set) &^ ci.Clear
|
462
|
+func (ac *activeConn) Send(commandName string, args ...interface{}) error {
|
|
|
|
463
|
+ pc := ac.pc
|
|
|
|
464
|
+ if pc == nil {
|
|
|
|
465
|
+ return errConnClosed
|
|
|
|
466
|
+ }
|
|
|
|
467
|
+ ci := lookupCommandInfo(commandName)
|
|
|
|
468
|
+ ac.state = (ac.state | ci.Set) &^ ci.Clear
|
|
449
|
return pc.c.Send(commandName, args...)
|
469
|
return pc.c.Send(commandName, args...)
|
|
450
|
}
|
470
|
}
|
|
451
|
|
471
|
|
|
452
|
-func (pc *pooledConnection) Flush() error {
|
472
|
+func (ac *activeConn) Flush() error {
|
|
|
|
473
|
+ pc := ac.pc
|
|
|
|
474
|
+ if pc == nil {
|
|
|
|
475
|
+ return errConnClosed
|
|
|
|
476
|
+ }
|
|
453
|
return pc.c.Flush()
|
477
|
return pc.c.Flush()
|
|
454
|
}
|
478
|
}
|
|
455
|
|
479
|
|
|
456
|
-func (pc *pooledConnection) Receive() (reply interface{}, err error) {
|
480
|
+func (ac *activeConn) Receive() (reply interface{}, err error) {
|
|
|
|
481
|
+ pc := ac.pc
|
|
|
|
482
|
+ if pc == nil {
|
|
|
|
483
|
+ return nil, errConnClosed
|
|
|
|
484
|
+ }
|
|
457
|
return pc.c.Receive()
|
485
|
return pc.c.Receive()
|
|
458
|
}
|
486
|
}
|
|
459
|
|
487
|
|
|
460
|
-func (pc *pooledConnection) ReceiveWithTimeout(timeout time.Duration) (reply interface{}, err error) {
|
488
|
+func (ac *activeConn) ReceiveWithTimeout(timeout time.Duration) (reply interface{}, err error) {
|
|
|
|
489
|
+ pc := ac.pc
|
|
|
|
490
|
+ if pc == nil {
|
|
|
|
491
|
+ return nil, errConnClosed
|
|
|
|
492
|
+ }
|
|
461
|
cwt, ok := pc.c.(ConnWithTimeout)
|
493
|
cwt, ok := pc.c.(ConnWithTimeout)
|
|
462
|
if !ok {
|
494
|
if !ok {
|
|
463
|
return nil, errTimeoutNotSupported
|
495
|
return nil, errTimeoutNotSupported
|
|
@@ -465,63 +497,64 @@ func (pc *pooledConnection) ReceiveWithTimeout(timeout time.Duration) (reply int |
|
@@ -465,63 +497,64 @@ func (pc *pooledConnection) ReceiveWithTimeout(timeout time.Duration) (reply int |
|
465
|
return cwt.ReceiveWithTimeout(timeout)
|
497
|
return cwt.ReceiveWithTimeout(timeout)
|
|
466
|
}
|
498
|
}
|
|
467
|
|
499
|
|
|
468
|
-type errorConnection struct{ err error }
|
500
|
+type errorConn struct{ err error }
|
|
469
|
|
501
|
|
|
470
|
-func (ec errorConnection) Do(string, ...interface{}) (interface{}, error) { return nil, ec.err }
|
|
|
|
471
|
-func (ec errorConnection) DoWithTimeout(time.Duration, string, ...interface{}) (interface{}, error) {
|
502
|
+func (ec errorConn) Do(string, ...interface{}) (interface{}, error) { return nil, ec.err }
|
|
|
|
503
|
+func (ec errorConn) DoWithTimeout(time.Duration, string, ...interface{}) (interface{}, error) {
|
|
472
|
return nil, ec.err
|
504
|
return nil, ec.err
|
|
473
|
}
|
505
|
}
|
|
474
|
-func (ec errorConnection) Send(string, ...interface{}) error { return ec.err }
|
|
|
|
475
|
-func (ec errorConnection) Err() error { return ec.err }
|
|
|
|
476
|
-func (ec errorConnection) Close() error { return nil }
|
|
|
|
477
|
-func (ec errorConnection) Flush() error { return ec.err }
|
|
|
|
478
|
-func (ec errorConnection) Receive() (interface{}, error) { return nil, ec.err }
|
|
|
|
479
|
-func (ec errorConnection) ReceiveWithTimeout(time.Duration) (interface{}, error) { return nil, ec.err }
|
506
|
+func (ec errorConn) Send(string, ...interface{}) error { return ec.err }
|
|
|
|
507
|
+func (ec errorConn) Err() error { return ec.err }
|
|
|
|
508
|
+func (ec errorConn) Close() error { return nil }
|
|
|
|
509
|
+func (ec errorConn) Flush() error { return ec.err }
|
|
|
|
510
|
+func (ec errorConn) Receive() (interface{}, error) { return nil, ec.err }
|
|
|
|
511
|
+func (ec errorConn) ReceiveWithTimeout(time.Duration) (interface{}, error) { return nil, ec.err }
|
|
480
|
|
512
|
|
|
481
|
type idleList struct {
|
513
|
type idleList struct {
|
|
482
|
count int
|
514
|
count int
|
|
483
|
- front, back *idleConn
|
515
|
+ front, back *poolConn
|
|
484
|
}
|
516
|
}
|
|
485
|
|
517
|
|
|
486
|
-type idleConn struct {
|
518
|
+type poolConn struct {
|
|
487
|
c Conn
|
519
|
c Conn
|
|
488
|
t time.Time
|
520
|
t time.Time
|
|
489
|
- next, prev *idleConn
|
521
|
+ created time.Time
|
|
|
|
522
|
+ next, prev *poolConn
|
|
490
|
}
|
523
|
}
|
|
491
|
|
524
|
|
|
492
|
-func (l *idleList) pushFront(ic *idleConn) {
|
|
|
|
493
|
- ic.next = l.front
|
|
|
|
494
|
- ic.prev = nil
|
525
|
+func (l *idleList) pushFront(pc *poolConn) {
|
|
|
|
526
|
+ pc.next = l.front
|
|
|
|
527
|
+ pc.prev = nil
|
|
495
|
if l.count == 0 {
|
528
|
if l.count == 0 {
|
|
496
|
- l.back = ic
|
529
|
+ l.back = pc
|
|
497
|
} else {
|
530
|
} else {
|
|
498
|
- l.front.prev = ic
|
531
|
+ l.front.prev = pc
|
|
499
|
}
|
532
|
}
|
|
500
|
- l.front = ic
|
533
|
+ l.front = pc
|
|
501
|
l.count++
|
534
|
l.count++
|
|
502
|
return
|
535
|
return
|
|
503
|
}
|
536
|
}
|
|
504
|
|
537
|
|
|
505
|
func (l *idleList) popFront() {
|
538
|
func (l *idleList) popFront() {
|
|
506
|
- ic := l.front
|
539
|
+ pc := l.front
|
|
507
|
l.count--
|
540
|
l.count--
|
|
508
|
if l.count == 0 {
|
541
|
if l.count == 0 {
|
|
509
|
l.front, l.back = nil, nil
|
542
|
l.front, l.back = nil, nil
|
|
510
|
} else {
|
543
|
} else {
|
|
511
|
- ic.next.prev = nil
|
|
|
|
512
|
- l.front = ic.next
|
544
|
+ pc.next.prev = nil
|
|
|
|
545
|
+ l.front = pc.next
|
|
513
|
}
|
546
|
}
|
|
514
|
- ic.next, ic.prev = nil, nil
|
547
|
+ pc.next, pc.prev = nil, nil
|
|
515
|
}
|
548
|
}
|
|
516
|
|
549
|
|
|
517
|
func (l *idleList) popBack() {
|
550
|
func (l *idleList) popBack() {
|
|
518
|
- ic := l.back
|
551
|
+ pc := l.back
|
|
519
|
l.count--
|
552
|
l.count--
|
|
520
|
if l.count == 0 {
|
553
|
if l.count == 0 {
|
|
521
|
l.front, l.back = nil, nil
|
554
|
l.front, l.back = nil, nil
|
|
522
|
} else {
|
555
|
} else {
|
|
523
|
- ic.prev.next = nil
|
|
|
|
524
|
- l.back = ic.prev
|
556
|
+ pc.prev.next = nil
|
|
|
|
557
|
+ l.back = pc.prev
|
|
525
|
}
|
558
|
}
|
|
526
|
- ic.next, ic.prev = nil, nil
|
559
|
+ pc.next, pc.prev = nil, nil
|
|
527
|
} |
560
|
} |