• Bryan C. Mills's avatar
    cmd/go/internal/lockedfile: add package and support library · 47dc9282
    Bryan C. Mills authored
    lockedfile.File passes through to os.File, with Open, Create, and OpenFile
    functions that mimic the corresponding os functions but acquire locks
    automatically, releasing them when the file is closed.
    
    lockedfile.Sentinel is a simplified wrapper around lockedfile.OpenFile for the
    common use-case of files that signal the status of idempotent tasks.
    
    lockedfile.Mutex is a Mutex-like synchronization primitive implemented in terms
    of file locks.
    
    lockedfile.Read is like ioutil.Read, but obtains a read-lock.
    
    lockedfile.Write is like ioutil.Write, but obtains a write-lock and can be used
    for read-only files with idempotent contents.
    
    Updates #26794
    
    Change-Id: I50f7132c71d2727862eed54411f3f27e1af55cad
    Reviewed-on: https://go-review.googlesource.com/c/145178
    Run-TryBot: Bryan C. Mills <bcmills@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: default avatarRuss Cox <rsc@golang.org>
    47dc9282
mutex.go 2.15 KB