Skip to content

Commit

Permalink
[v2.81][bugfix] replace task.yield to thead.sleep(1), fix cpu 100% cost
Browse files Browse the repository at this point in the history
  • Loading branch information
psygames committed Aug 27, 2024
1 parent c57bed0 commit d557324
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Assets/UnityWebSocket/Scripts/Runtime/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public static class Settings
public const string QQ_GROUP_LINK = "https://qm.qq.com/cgi-bin/qm/qr?k=KcexYJ9aYwogFXbj2aN0XHH5b2G7ICmd";
public const string EMAIL = "[email protected]";
public const string AUHTOR = "psygames";
public const string VERSION = "2.8.0";
public const string VERSION = "2.8.1";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,13 @@ private async void StartSendTask()
{
while (!closeProcessing)
{
while (!closeProcessing && sendQueue.TryDequeue(out var buffer))
while (!closeProcessing && sendQueue.Count > 0 && sendQueue.TryDequeue(out var buffer))
{
Log($"Send, type: {buffer.type}, size: {buffer.data.Length}, queue left: {sendQueue.Count}");
await socket.SendAsync(new ArraySegment<byte>(buffer.data), buffer.type, true, CancellationToken.None);
}
await Task.Yield();
Thread.Sleep(1);
}

if (closeProcessing)
{
CleanSendQueue();
Expand Down Expand Up @@ -279,7 +278,7 @@ private void HandleError(Exception exception)

internal void Update()
{
while (receiveQueue.TryDequeue(out var e))
while (receiveQueue.Count > 0 && receiveQueue.TryDequeue(out var e))
{
if (e is CloseEventArgs)
{
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 2.8.0
bundleVersion: 2.8.1
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down

1 comment on commit d557324

@nukadelic
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.