package runbook

import (
	"sync"
)

var globalTargetLocks sync.Map

type targetLock struct {
	mu sync.Mutex
}

func acquireTargetLock(target string) func() {
	if target == "" {
		return func() {}
	}
	v, _ := globalTargetLocks.LoadOrStore(target, &targetLock{})
	lk := v.(*targetLock)
	lk.mu.Lock()
	return func() { lk.mu.Unlock() }
}
