浏览代码

fix mux send window size counting

ffdfgdfg 5 年之前
父节点
当前提交
5e1b0be81c
共有 1 个文件被更改,包括 14 次插入1 次删除
  1. 14 1
      lib/mux/conn.go

+ 14 - 1
lib/mux/conn.go

@@ -446,7 +446,20 @@ func (Self *SendWindow) allow() {
 }
 
 func (Self *SendWindow) sent(sentSize uint32) {
-	atomic.AddUint64(&Self.remainingWait, ^(uint64(sentSize)<<dequeueBits - 1))
+	var remaining, wait uint32
+	for {
+		ptrs := atomic.LoadUint64(&Self.remainingWait)
+		remaining, wait = Self.unpack(ptrs)
+		if remaining >= sentSize {
+			atomic.AddUint64(&Self.remainingWait, ^(uint64(sentSize)<<dequeueBits - 1))
+			break
+		} else {
+			if atomic.CompareAndSwapUint64(&Self.remainingWait, ptrs, Self.pack(0, wait)) {
+				// just keep the wait status, it will be wait in the next loop
+				break
+			}
+		}
+	}
 }
 
 func (Self *SendWindow) WriteTo() (p []byte, sendSize uint32, part bool, err error) {