in linux/handler.go [59:89]
func (h *KeyHandler) Get(keyID string) (tpmutil.Handle, func(success bool), error) {
lock := h.lockKey(keyID)
h.lock.Lock()
defer h.lock.Unlock()
handle, ok := h.handles[keyID]
if ok {
return handle, func(bool) { lock.Unlock() }, nil
}
next, err := h.nextAvailable()
if err != nil {
return 0, nil, err
}
h.inFlightHandles[keyID] = next
flush := func(success bool) {
h.lock.Lock()
if success {
h.handles[keyID] = next
}
delete(h.inFlightLocks, keyID)
delete(h.inFlightHandles, keyID)
lock.Unlock()
h.lock.Unlock()
}
return next, flush, nil
}