internal static void P2PBarrierRequest(this Trinity.Storage.MemoryCloud storage, int taskId) { TrinityMessage msg = new TrinityMessage(TrinityMessageType.PRESERVED_SYNC, (ushort)RequestType.P2PBarrier, sizeof(int)); *(int *)(msg.Buffer + TrinityMessage.Offset) = taskId; SpinLockInt32.GetLock(ref spin_lock); if (BSPCheckInCount.ContainsKey(taskId)) { BSPCheckInCount[taskId]++; } else { BSPCheckInCount[taskId] = 1; } SpinLockInt32.ReleaseLock(ref spin_lock); Parallel.For(0, Global.ServerCount, i => { if (i != Global.MyServerId) { storage.SendMessageToServer(i, msg); } } ); int retry = 2048; while (true) { SpinLockInt32.GetLock(ref spin_lock); if (BSPCheckInCount[taskId] == Global.ServerCount) { BSPCheckInCount.Remove(taskId); SpinLockInt32.ReleaseLock(ref spin_lock); return; } SpinLockInt32.ReleaseLock(ref spin_lock); if (--retry < 1024) { if (retry > 0) { Thread.Yield(); } else { Thread.Sleep(1); } } } }
internal static void P2PBarrierHandler(SynReqArgs args) { int taskId; taskId = *(int *)(args.Buffer + args.Offset); SpinLockInt32.GetLock(ref spin_lock); if (BSPCheckInCount.ContainsKey(taskId)) { BSPCheckInCount[taskId]++; } else { BSPCheckInCount[taskId] = 1; } SpinLockInt32.ReleaseLock(ref spin_lock); }