diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-11-24 08:04:20 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-11-24 08:55:49 +0000 |
| commit | 9174555f6d933d77dace419771065710ef6df014 (patch) | |
| tree | e272115ab3fa416d5105163934b5faa1f0c5fc5c /pkg/instance | |
| parent | a6deb8053825b4c7024c2b04f5d4f5a12ace1272 (diff) | |
pkg/osutil: move Semaphore from pkg/instance
Semaphore is a very low-level primitive type,
while pkg/instance is a very high-level package with lots of deps.
Semaphore does not belong there, and may lead to cyclic deps
if we use it more. Move it to pkg/osutil. It's not really OS-specific,
but we don't have a better package.
Diffstat (limited to 'pkg/instance')
| -rw-r--r-- | pkg/instance/instance.go | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index b4460e3ab..df0d74b98 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -40,8 +40,8 @@ type Env interface { type env struct { cfg *mgrconfig.Config optionalFlags bool - buildSem *Semaphore - testSem *Semaphore + buildSem *osutil.Semaphore + testSem *osutil.Semaphore } type BuildKernelConfig struct { @@ -56,7 +56,7 @@ type BuildKernelConfig struct { BuildCPUs int } -func NewEnv(cfg *mgrconfig.Config, buildSem, testSem *Semaphore) (Env, error) { +func NewEnv(cfg *mgrconfig.Config, buildSem, testSem *osutil.Semaphore) (Env, error) { if !vm.AllowsOvercommit(cfg.Type) { return nil, fmt.Errorf("test instances are not supported for %v VMs", cfg.Type) } @@ -508,40 +508,6 @@ func RunnerCmd(prog, fwdAddr, os, arch string, poolIdx, vmIdx int, threaded, new "-threaded=%t -new-env=%t", prog, fwdAddr, os, arch, poolIdx, vmIdx, threaded, newEnv) } -type Semaphore struct { - ch chan struct{} -} - -func NewSemaphore(count int) *Semaphore { - s := &Semaphore{ - ch: make(chan struct{}, count), - } - for i := 0; i < count; i++ { - s.Signal() - } - return s -} - -func (s *Semaphore) Wait() { - <-s.ch -} - -func (s *Semaphore) WaitC() <-chan struct{} { - return s.ch -} - -func (s *Semaphore) Available() int { - return len(s.ch) -} - -func (s *Semaphore) Signal() { - if av := s.Available(); av == cap(s.ch) { - // Not super reliable, but let it be here just in case. - panic(fmt.Sprintf("semaphore capacity (%d) is exceeded (%d)", cap(s.ch), av)) - } - s.ch <- struct{}{} -} - // RunSmokeTest executes syz-manager in the smoke test mode and returns two values: // The crash report, if the testing failed. // An error if there was a problem not related to testing the kernel. |
