Skip to content

Commit

Permalink
修复StaticField编译错误,瞬间检测出Session.RpcId这个多线程竞争的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
egametang committed Jul 18, 2023
1 parent 6619a1c commit ed303ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Unity/Assets/Scripts/Core/World/Singleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class Singleton<T>: ASingleton where T: Singleton<T>
[StaticField]
private static T instance;

[StaticField]
public static T Instance
{
get
Expand Down
1 change: 1 addition & 0 deletions Unity/Assets/Scripts/Core/World/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class World: IDisposable
[StaticField]
private static World instance;

[StaticField]
public static World Instance
{
get
Expand Down
6 changes: 3 additions & 3 deletions Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void OnResponse(this Session self, IResponse response)

public static async ETTask<IResponse> Call(this Session self, IRequest request, ETCancellationToken cancellationToken)
{
int rpcId = ++Session.RpcId;
int rpcId = ++self.RpcId;
RpcInfo rpcInfo = new RpcInfo(request);
self.requestCallbacks[rpcId] = rpcInfo;
request.RpcId = rpcId;
Expand Down Expand Up @@ -102,7 +102,7 @@ void CancelAction()

public static async ETTask<IResponse> Call(this Session self, IRequest request, int time = 0)
{
int rpcId = ++Session.RpcId;
int rpcId = ++self.RpcId;
RpcInfo rpcInfo = new(request);
self.requestCallbacks[rpcId] = rpcInfo;
request.RpcId = rpcId;
Expand Down Expand Up @@ -150,7 +150,7 @@ public sealed class Session: Entity, IAwake<AService>, IDestroy
{
public AService AService { get; set; }

public static int RpcId
public int RpcId
{
get;
set;
Expand Down

0 comments on commit ed303ff

Please sign in to comment.