You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/05/16 23:15:15 UTC
cvs commit: logging-log4net/src/DateFormatter AbsoluteTimeDateFormatter.cs
nicko 2004/05/16 14:15:15
Modified: src/DateFormatter AbsoluteTimeDateFormatter.cs
Log:
Added locking to date formatter where the shared static buffer is written to.
Revision Changes Path
1.4 +18 -8 logging-log4net/src/DateFormatter/AbsoluteTimeDateFormatter.cs
Index: AbsoluteTimeDateFormatter.cs
===================================================================
RCS file: /home/cvs/logging-log4net/src/DateFormatter/AbsoluteTimeDateFormatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbsoluteTimeDateFormatter.cs 23 Feb 2004 03:18:03 -0000 1.3
+++ AbsoluteTimeDateFormatter.cs 16 May 2004 21:15:15 -0000 1.4
@@ -96,19 +96,29 @@
// the previously calculated time string
if (s_lastTimeToTheSecond != currentTimeToTheSecond)
{
- // We are in a new second.
- s_lastTimeToTheSecond = currentTimeToTheSecond;
- s_lastTimeBuf.Length = 0;
+ // lock so that only one thread can use the buffer and
+ // update the s_lastTimeToTheSecond and s_lastTimeString
- // Calculate the new string for this second
- FormatDateWithoutMillis(dateToFormat, s_lastTimeBuf);
+ // PERF: Try removing this lock and using a new StringBuilder each time
+ lock(s_lastTimeBuf)
+ {
+ if (s_lastTimeToTheSecond != currentTimeToTheSecond)
+ {
+ // We are in a new second.
+ s_lastTimeBuf.Length = 0;
- // Store the time as a string (we only have to do this once per second)
- s_lastTimeString = s_lastTimeBuf.ToString();
+ // Calculate the new string for this second
+ FormatDateWithoutMillis(dateToFormat, s_lastTimeBuf);
+
+ // Store the time as a string (we only have to do this once per second)
+ s_lastTimeString = s_lastTimeBuf.ToString();
+ s_lastTimeToTheSecond = currentTimeToTheSecond;
+ }
+ }
}
writer.Write(s_lastTimeString);
- // Append the current milli info
+ // Append the current millisecond info
writer.Write(',');
int millis = dateToFormat.Millisecond;
if (millis < 100)