Skip to content

Commit

Permalink
#21 Sometimes flow ids are clashed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay.Pianikov authored and Nikolay.Pianikov committed May 31, 2017
1 parent 73d0799 commit 948e832
Showing 1 changed file with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace JetBrains.TeamCity.ServiceMessages.Write.Special.Impl
{
using System;
using System.Globalization;
using System.Threading;

Expand All @@ -25,22 +24,14 @@ namespace JetBrains.TeamCity.ServiceMessages.Write.Special.Impl
/// </summary>
public class DefaultFlowIdGenerator : IFlowIdGenerator
{
private int _ids;
private static long ourIds;

/// <summary>
/// Generates new unique FlowId
/// </summary>
public string NewFlowId()
{
return (
#if !NET35 && !NET40
Interlocked.Increment(ref _ids)
#else
Interlocked.Increment(ref _ids) << (27
+ (Thread.CurrentThread.ManagedThreadId << 21)
+ Environment.TickCount % int.MaxValue)
#endif
).ToString(CultureInfo.InvariantCulture);
return Interlocked.Increment(ref ourIds).ToString(CultureInfo.InvariantCulture);
}
}
}

0 comments on commit 948e832

Please sign in to comment.