MCPcopy Create free account
hub / github.com/coder/coder / popLeastRecentlyUsedSession

Method popLeastRecentlyUsedSession

agent/agentssh/x11.go:272–292  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

270}
271
272func (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
294func (x *x11Forwarder) evictLeastRecentlyUsedSession() {
295 lru := x.popLeastRecentlyUsedSession()

Callers 1

Calls 2

LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected