()
| 270 | } |
| 271 | |
| 272 | func (x *x11Forwarder) popLeastRecentlyUsedSession() *x11Session { |
| 273 | x.mu.Lock() |
| 274 | defer x.mu.Unlock() |
| 275 | var lru *x11Session |
| 276 | for s := range x.sessions { |
| 277 | if lru == nil { |
| 278 | lru = s |
| 279 | continue |
| 280 | } |
| 281 | if s.usedAt.Before(lru.usedAt) { |
| 282 | lru = s |
| 283 | continue |
| 284 | } |
| 285 | } |
| 286 | if lru == nil { |
| 287 | x.logger.Debug(context.Background(), "tried to pop from empty set of X11 sessions") |
| 288 | return nil |
| 289 | } |
| 290 | delete(x.sessions, lru) |
| 291 | return lru |
| 292 | } |
| 293 | |
| 294 | func (x *x11Forwarder) evictLeastRecentlyUsedSession() { |
| 295 | lru := x.popLeastRecentlyUsedSession() |
no test coverage detected