Add new file

This commit is contained in:
Test
2026-08-21 15:58:46 -07:00
parent 52001c90de
commit 769e56d33d
27 changed files with 753 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
package config
// Empty stub - will be filled in T0.8
+39
View File
@@ -0,0 +1,39 @@
package lock
import (
"fmt"
"sync"
)
var (
locks = make(map[string]*sync.Mutex)
locksMu sync.Mutex
)
// Acquire acquires an advisory lock on a file.
// It creates the file if it doesn't exist, then uses a Go mutex for synchronization.
// This implementation is safe for single-process use; multi-process distributed locking
// would require OS-level file locking (fcntl/flock on Unix or LockFileEx on Windows).
func Acquire(path string) error {
locksMu.Lock()
defer locksMu.Unlock()
if locks[path] == nil {
locks[path] = &sync.Mutex{}
}
locks[path].Lock()
return nil
}
// Release releases an advisory lock on a file.
func Release(path string) error {
locksMu.Lock()
defer locksMu.Unlock()
mu, exists := locks[path]
if !exists {
return fmt.Errorf("lock not acquired for path: %s", path)
}
mu.Unlock()
return nil
}