all: use Go 1.19 and its atomic types

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Brad Fitzpatrick
2022-08-30 07:43:11 -07:00
committed by Jason A. Donenfeld
parent d1d08426b2
commit b51010ba13
20 changed files with 156 additions and 288 deletions

View File

@@ -29,7 +29,7 @@ type pipe struct {
type messageBytePipe struct {
pipe
writeClosed int32
writeClosed atomic.Bool
readEOF bool
}
@@ -51,17 +51,17 @@ func (f *pipe) SetDeadline(t time.Time) error {
// CloseWrite closes the write side of a message pipe in byte mode.
func (f *messageBytePipe) CloseWrite() error {
if !atomic.CompareAndSwapInt32(&f.writeClosed, 0, 1) {
if !f.writeClosed.CompareAndSwap(false, true) {
return io.ErrClosedPipe
}
err := f.file.Flush()
if err != nil {
atomic.StoreInt32(&f.writeClosed, 0)
f.writeClosed.Store(false)
return err
}
_, err = f.file.Write(nil)
if err != nil {
atomic.StoreInt32(&f.writeClosed, 0)
f.writeClosed.Store(false)
return err
}
return nil
@@ -70,7 +70,7 @@ func (f *messageBytePipe) CloseWrite() error {
// Write writes bytes to a message pipe in byte mode. Zero-byte writes are ignored, since
// they are used to implement CloseWrite.
func (f *messageBytePipe) Write(b []byte) (int, error) {
if atomic.LoadInt32(&f.writeClosed) != 0 {
if f.writeClosed.Load() {
return 0, io.ErrClosedPipe
}
if len(b) == 0 {