mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-18 05:43:42 +00:00
enhance: make shared tool cache safe at any capacity (#1401)
Co-authored-by: bircni <[email protected]>
This commit is contained in:
1 parent
84c0fcd1fa
commit
a021d3139d
9 files changed
+121
-11
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package run
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"gitea.com/gitea/runner/internal/pkg/config"
|
||||
)
|
||||
|
||||
// slotAllocator hands out the lowest free slot, so slot numbers stay below capacity.
|
||||
type slotAllocator struct {
|
||||
mu sync.Mutex
|
||||
used []bool
|
||||
}
|
||||
|
||||
func (a *slotAllocator) acquire() int {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
slot := slices.Index(a.used, false)
|
||||
if slot < 0 {
|
||||
slot = len(a.used)
|
||||
a.used = append(a.used, false)
|
||||
}
|
||||
a.used[slot] = true
|
||||
return slot
|
||||
}
|
||||
|
||||
func (a *slotAllocator) release(slot int) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
a.used[slot] = false
|
||||
}
|
||||
|
||||
// toolCacheSlot leaves slot 0 unnamed, so it keeps the cache a runner had before slots existed.
|
||||
func toolCacheSlot(mode string, slot int) string {
|
||||
if mode != config.ToolCacheModeShared || slot == 0 {
|
||||
return ""
|
||||
}
|
||||
return strconv.Itoa(slot)
|
||||
}
|
||||
Reference in new issue
Block a user