Commit dfebeb7d authored by Jeremy Meng's avatar Jeremy Meng

Use Volatile.{Read,Write} instead.

parent 905f7d7c
...@@ -941,11 +941,11 @@ private void OnHeartbeat() ...@@ -941,11 +941,11 @@ private void OnHeartbeat()
internal long LastHeartbeatSecondsAgo { internal long LastHeartbeatSecondsAgo {
get { get {
if (pulse == null) return -1; if (pulse == null) return -1;
return unchecked(Environment.TickCount - Thread.VolatileRead(ref lastHeartbeatTicks)) / 1000; return unchecked(Environment.TickCount - Volatile.Read(ref lastHeartbeatTicks)) / 1000;
} }
} }
internal static long LastGlobalHeartbeatSecondsAgo internal static long LastGlobalHeartbeatSecondsAgo
{ get { return unchecked(Environment.TickCount - Thread.VolatileRead(ref lastGlobalHeartbeatTicks)) / 1000; } } { get { return unchecked(Environment.TickCount - Volatile.Read(ref lastGlobalHeartbeatTicks)) / 1000; } }
internal CompletionManager UnprocessableCompletionManager { get { return unprocessableCompletionManager; } } internal CompletionManager UnprocessableCompletionManager { get { return unprocessableCompletionManager; } }
......
...@@ -394,7 +394,7 @@ internal void OnHeartbeat(bool ifConnectedOnly) ...@@ -394,7 +394,7 @@ internal void OnHeartbeat(bool ifConnectedOnly)
switch (state) switch (state)
{ {
case (int)State.Connecting: case (int)State.Connecting:
int connectTimeMilliseconds = unchecked(Environment.TickCount - Thread.VolatileRead(ref connectStartTicks)); int connectTimeMilliseconds = unchecked(Environment.TickCount - Volatile.Read(ref connectStartTicks));
if (connectTimeMilliseconds >= multiplexer.RawConfig.ConnectTimeout) if (connectTimeMilliseconds >= multiplexer.RawConfig.ConnectTimeout)
{ {
Trace("Aborting connect"); Trace("Aborting connect");
......
...@@ -93,7 +93,7 @@ public PhysicalConnection(PhysicalBridge bridge) ...@@ -93,7 +93,7 @@ public PhysicalConnection(PhysicalBridge bridge)
public void BeginConnect(TextWriter log) public void BeginConnect(TextWriter log)
{ {
Thread.VolatileWrite(ref firstUnansweredWriteTickCount, 0); Volatile.Write(ref firstUnansweredWriteTickCount, 0);
var endpoint = this.bridge.ServerEndPoint.EndPoint; var endpoint = this.bridge.ServerEndPoint.EndPoint;
multiplexer.Trace("Connecting...", physicalName); multiplexer.Trace("Connecting...", physicalName);
...@@ -113,7 +113,7 @@ public long LastWriteSecondsAgo ...@@ -113,7 +113,7 @@ public long LastWriteSecondsAgo
{ {
get get
{ {
return unchecked(Environment.TickCount - Thread.VolatileRead(ref lastWriteTickCount)) / 1000; return unchecked(Environment.TickCount - Volatile.Read(ref lastWriteTickCount)) / 1000;
} }
} }
...@@ -193,9 +193,9 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, ref Socket ...@@ -193,9 +193,9 @@ public void RecordConnectionFailed(ConnectionFailureType failureType, ref Socket
if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0) if (isCurrent && Interlocked.CompareExchange(ref failureReported, 1, 0) == 0)
{ {
managerState = SocketManager.ManagerState.RecordConnectionFailed_ReportFailure; managerState = SocketManager.ManagerState.RecordConnectionFailed_ReportFailure;
int now = Environment.TickCount, lastRead = Thread.VolatileRead(ref lastReadTickCount), lastWrite = Thread.VolatileRead(ref lastWriteTickCount), int now = Environment.TickCount, lastRead = Volatile.Read(ref lastReadTickCount), lastWrite = Volatile.Read(ref lastWriteTickCount),
lastBeat = Thread.VolatileRead(ref lastBeatTickCount); lastBeat = Volatile.Read(ref lastBeatTickCount);
int unansweredRead = Thread.VolatileRead(ref firstUnansweredWriteTickCount); int unansweredRead = Volatile.Read(ref firstUnansweredWriteTickCount);
var exMessage = new StringBuilder(failureType + " on " + Format.ToString(bridge.ServerEndPoint.EndPoint) + "/" + connectionType); var exMessage = new StringBuilder(failureType + " on " + Format.ToString(bridge.ServerEndPoint.EndPoint) + "/" + connectionType);
var data = new List<Tuple<string, string>> var data = new List<Tuple<string, string>>
...@@ -903,7 +903,7 @@ private bool ProcessReadBytes(int bytesRead) ...@@ -903,7 +903,7 @@ private bool ProcessReadBytes(int bytesRead)
Interlocked.Exchange(ref lastReadTickCount, Environment.TickCount); Interlocked.Exchange(ref lastReadTickCount, Environment.TickCount);
// reset unanswered write timestamp // reset unanswered write timestamp
Thread.VolatileWrite(ref firstUnansweredWriteTickCount, 0); Volatile.Write(ref firstUnansweredWriteTickCount, 0);
ioBufferBytes += bytesRead; ioBufferBytes += bytesRead;
multiplexer.Trace("More bytes available: " + bytesRead + " (" + ioBufferBytes + ")", physicalName); multiplexer.Trace("More bytes available: " + bytesRead + " (" + ioBufferBytes + ")", physicalName);
...@@ -1066,7 +1066,7 @@ RawResult TryParseResult(byte[] buffer, ref int offset, ref int count) ...@@ -1066,7 +1066,7 @@ RawResult TryParseResult(byte[] buffer, ref int offset, ref int count)
public void CheckForStaleConnection(ref SocketManager.ManagerState managerState) public void CheckForStaleConnection(ref SocketManager.ManagerState managerState)
{ {
int firstUnansweredWrite; int firstUnansweredWrite;
firstUnansweredWrite = Thread.VolatileRead(ref firstUnansweredWriteTickCount); firstUnansweredWrite = Volatile.Read(ref firstUnansweredWriteTickCount);
DebugEmulateStaleConnection(ref firstUnansweredWrite); DebugEmulateStaleConnection(ref firstUnansweredWrite);
......
...@@ -484,7 +484,7 @@ internal void OnFullyEstablished(PhysicalConnection connection) ...@@ -484,7 +484,7 @@ internal void OnFullyEstablished(PhysicalConnection connection)
internal int LastInfoReplicationCheckSecondsAgo internal int LastInfoReplicationCheckSecondsAgo
{ {
get { return unchecked(Environment.TickCount - Thread.VolatileRead(ref lastInfoReplicationCheckTicks)) / 1000; } get { return unchecked(Environment.TickCount - Volatile.Read(ref lastInfoReplicationCheckTicks)) / 1000; }
} }
private EndPoint masterEndPoint; private EndPoint masterEndPoint;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment