From 2f9b072abdda177c613a471eb4cd49cad8c9e2ec Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 31 Dec 2021 17:47:34 +0800 Subject: [PATCH] add lock --- syscalls_windows.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syscalls_windows.go b/syscalls_windows.go index 3a25185..20418bb 100644 --- a/syscalls_windows.go +++ b/syscalls_windows.go @@ -359,6 +359,9 @@ func (w *wintunRWC) Write(b []byte) (int, error) { } func (w *wintunRWC) Read(b []byte) (int, error) { + w.mu.Lock() + defer w.mu.Unlock() + n := 0 if w.readbuf != nil { @@ -380,8 +383,6 @@ RETRY: } start := nanotime() shouldSpin := atomic.LoadUint64(&w.rate.current) >= spinloopRateThreshold && uint64(start-atomic.LoadInt64(&w.rate.nextStartTime)) <= rateMeasurementGranularity*2 - w.mu.Lock() - defer w.mu.Unlock() for { packet, err := w.s.ReceivePacket() switch err {