Browse Source

Use atomic long read.

Signed-off-by: noisyfox <timemanager.rick@gmail.com>
tags/3.3
noisyfox 8 years ago
parent
commit
a7b0ce5bcb
2 changed files with 13 additions and 13 deletions
  1. +12
    -12
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +1
    -1
      shadowsocks-csharp/View/LogForm.cs

+ 12
- 12
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -33,8 +33,10 @@ namespace Shadowsocks.Controller
public AvailabilityStatistics availabilityStatistics = AvailabilityStatistics.Instance;
public StatisticsStrategyConfiguration StatisticsConfiguration { get; private set; }
public long inboundCounter = 0;
public long outboundCounter = 0;
private long _inboundCounter = 0;
private long _outboundCounter = 0;
public long InboundCounter => Interlocked.Read(ref _inboundCounter);
public long OutboundCounter => Interlocked.Read(ref _outboundCounter);
public QueueLast<TrafficPerSecond> traffic;
private bool stopped = false;
@@ -364,7 +366,7 @@ namespace Shadowsocks.Controller
public void UpdateInboundCounter(Server server, long n)
{
Interlocked.Add(ref inboundCounter, n);
Interlocked.Add(ref _inboundCounter, n);
if (_config.availabilityStatistics)
{
availabilityStatistics.UpdateInboundCounter(server, n);
@@ -373,7 +375,7 @@ namespace Shadowsocks.Controller
public void UpdateOutboundCounter(Server server, long n)
{
Interlocked.Add(ref outboundCounter, n);
Interlocked.Add(ref _outboundCounter, n);
if (_config.availabilityStatistics)
{
availabilityStatistics.UpdateOutboundCounter(server, n);
@@ -579,19 +581,17 @@ namespace Shadowsocks.Controller
{
TrafficPerSecond previous = traffic.Last;
TrafficPerSecond current = new TrafficPerSecond();
current.inboundCounter = inboundCounter;
current.outboundCounter = outboundCounter;
current.inboundIncreasement = inboundCounter - previous.inboundCounter;
current.outboundIncreasement = outboundCounter - previous.outboundCounter;
var inbound = current.inboundCounter = InboundCounter;
var outbound = current.outboundCounter = OutboundCounter;
current.inboundIncreasement = inbound - previous.inboundCounter;
current.outboundIncreasement = outbound - previous.outboundCounter;
traffic.Enqueue(current);
if (traffic.Count > queueMaxSize)
traffic.Dequeue();
if (TrafficChanged != null)
{
TrafficChanged(this, new EventArgs());
}
TrafficChanged?.Invoke(this, new EventArgs());
Thread.Sleep(1000);
}


+ 1
- 1
shadowsocks-csharp/View/LogForm.cs View File

@@ -171,7 +171,7 @@ namespace Shadowsocks.View
}
this.Text = I18N.GetString("Log Viewer") +
$" [in: {Utils.FormatBandwidth(controller.inboundCounter)}, out: {Utils.FormatBandwidth(controller.outboundCounter)}]";
$" [in: {Utils.FormatBandwidth(controller.InboundCounter)}, out: {Utils.FormatBandwidth(controller.OutboundCounter)}]";
}
private void LogForm_Load(object sender, EventArgs e)


Loading…
Cancel
Save