fix #249, use sync.Mutex instead at 32bit arch

This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent d3985edd76
commit d4dba8eb69
4 changed files with 38 additions and 11 deletions

View File

@@ -4,7 +4,6 @@ import (
"io"
"net"
"reflect"
"sync/atomic"
"syscall"
"github.com/e1732a364fed/v2ray_simple/utils"
@@ -339,7 +338,7 @@ func Relay(realTargetAddr *Addr, rc, lc io.ReadWriteCloser, identity uint32, dow
rc.Close()
if uploadByteCount != nil {
atomic.AddUint64(uploadByteCount, uint64(n))
utils.AtomicAddUint64(uploadByteCount, uint64(n))
}
}()
@@ -357,7 +356,7 @@ func Relay(realTargetAddr *Addr, rc, lc io.ReadWriteCloser, identity uint32, dow
rc.Close()
if downloadByteCount != nil {
atomic.AddUint64(downloadByteCount, uint64(n))
utils.AtomicAddUint64(downloadByteCount, uint64(n))
}
return n
} else {
@@ -368,7 +367,7 @@ func Relay(realTargetAddr *Addr, rc, lc io.ReadWriteCloser, identity uint32, dow
rc.Close()
if uploadByteCount != nil {
atomic.AddUint64(uploadByteCount, uint64(n))
utils.AtomicAddUint64(uploadByteCount, uint64(n))
}
}()
@@ -379,7 +378,7 @@ func Relay(realTargetAddr *Addr, rc, lc io.ReadWriteCloser, identity uint32, dow
rc.Close()
if downloadByteCount != nil {
atomic.AddUint64(downloadByteCount, uint64(n))
utils.AtomicAddUint64(downloadByteCount, uint64(n))
}
return n
}

View File

@@ -3,7 +3,6 @@ package netLayer
import (
"reflect"
"sync"
"sync/atomic"
"time"
"github.com/e1732a364fed/v2ray_simple/utils"
@@ -134,7 +133,7 @@ func RelayUDP(rc, lc MsgConn, downloadByteCount, uploadByteCount *uint64) uint64
}
if uploadByteCount != nil {
atomic.AddUint64(uploadByteCount, count)
utils.AtomicAddUint64(uploadByteCount, count)
}
}()
@@ -185,7 +184,7 @@ func relayUDP_rc_toLC(rc, lc MsgConn, downloadByteCount *uint64, mutex *sync.RWM
}
if downloadByteCount != nil {
atomic.AddUint64(downloadByteCount, count)
utils.AtomicAddUint64(downloadByteCount, count)
}
return count, rcwrong
@@ -289,7 +288,7 @@ func RelayUDP_separate(rc, lc MsgConn, firstAddr *Addr, downloadByteCount, uploa
lc.Close()
if uploadByteCount != nil {
atomic.AddUint64(uploadByteCount, count)
utils.AtomicAddUint64(uploadByteCount, count)
}
}()
@@ -329,7 +328,7 @@ func RelayUDP_separate(rc, lc MsgConn, firstAddr *Addr, downloadByteCount, uploa
// CopyMsgFromP2C(rc, lc, &dbc)
// if downloadByteCount != nil {
// atomic.AddUint64(downloadByteCount, dbc)
// utils.AtomicAddUint64(downloadByteCount, dbc)
// }
// return dbc
@@ -351,7 +350,7 @@ func RelayUDP_separate(rc, lc MsgConn, firstAddr *Addr, downloadByteCount, uploa
// }
// if countPtr != nil {
// atomic.AddUint64(countPtr, bc)
// utils.AtomicAddUint64(countPtr, bc)
// }
// }

17
utils/arch_32.go Normal file
View File

@@ -0,0 +1,17 @@
//go:build 386 || arm || mips || mipsle
package utils
import (
"sync"
)
var uint64Mutex sync.Mutex
// Use AddUint64 at 64bit arch, use sync.mutex at 32bit arch
func AtomicAddUint64(u64 *uint64, delta uint64) {
uint64Mutex.Lock()
*u64 = *u64 + delta
uint64Mutex.Unlock()
}

12
utils/arch_64.go Normal file
View File

@@ -0,0 +1,12 @@
//go:build amd64 || arm64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || s390x || wasm
package utils
import (
"sync/atomic"
)
// Use atomic.AddUint64 at 64bit arch, use sync.mutex at 32bit arch
func AtomicAddUint64(u64 *uint64, delta uint64) {
atomic.AddUint64(u64, delta)
}