[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET Class Library (pnetlib)
From: |
Klaus Treichel |
Subject: |
[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET Class Library (pnetlib) branch, master, updated. 2dba8321b1d7110e25d57dd465aea9229a1865c1 |
Date: |
Mon, 23 Nov 2009 08:23:44 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET Class Library (pnetlib)".
The branch, master has been updated
via 2dba8321b1d7110e25d57dd465aea9229a1865c1 (commit)
via 3ecb2aa652054910677cd548b2ce50e7be9199b1 (commit)
via f590966fddad8466ea0139f8340e134a163fd2e3 (commit)
from 34bc87b6dc6c3f9979bf34747d8dd4894418ea84 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/pnetlib.git/commit/?id=2dba8321b1d7110e25d57dd465aea9229a1865c1
commit 2dba8321b1d7110e25d57dd465aea9229a1865c1
Author: Klaus Treichel <address@hidden>
Date: Mon Nov 23 09:23:09 2009 +0100
Replace the static stdin, stdout and stderr members in System.Console by
private singleton classes to initialize them in static constructors and
avoid the lock on accessing the corresponding properties.
diff --git a/ChangeLog b/ChangeLog
index 4d3008b..bb5f53f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2009-11-23 Klaus Treichel <address@hidden>
+ * runtime/System/Console.cs: Replace the static stdin, stdout and stderr
+ members by private singleton classes to initialize them in static
+ constructors and avoid the lock on accessing the corresponding
+ properties.
+
* runtime/System/Type.cs (DefaultBinder): Create a new DefaultBinder if
the cached version is null instead of not null.
diff --git a/runtime/System/Console.cs b/runtime/System/Console.cs
index 7bdad65..f8414f8 100644
--- a/runtime/System/Console.cs
+++ b/runtime/System/Console.cs
@@ -31,10 +31,59 @@ public sealed class Console
#if !CONFIG_SMALL_CONSOLE
- // Cached copies of the stdin, stdout, and stderr streams.
- private static TextReader stdin = null;
- private static TextWriter stdout = null;
- private static TextWriter stderr = null;
+ /*
+ * Helper classes to initialize the streams only on first access.
+ */
+ private class StdIn
+ {
+ public static TextReader stream;
+
+ static StdIn()
+ {
+ stream = new StdReader(0);
+ }
+
+ }
+
+ private class StdOut
+ {
+ public static TextWriter stream;
+
+ static StdOut()
+ {
+ Encoding encoding = Encoding.Default;
+ StreamWriter writer;
+
+ if(encoding is UTF8Encoding)
+ {
+ // Disable the preamble if
UTF-8.
+ encoding = new UTF8Encoding();
+ }
+ writer = new StreamWriter(new
StdStream(1), encoding);
+ writer.AutoFlush = true;
+ stream =
TextWriter.Synchronized(writer);
+ }
+ }
+
+ private class StdErr
+ {
+ public static TextWriter stream;
+
+ static StdErr()
+ {
+ Encoding encoding = Encoding.Default;
+ StreamWriter writer;
+
+ if(encoding is UTF8Encoding)
+ {
+ // Disable the preamble if
UTF-8.
+ encoding = new UTF8Encoding();
+ }
+ writer = new StreamWriter(new
StdStream(2), encoding);
+ writer.AutoFlush = true;
+ stream =
TextWriter.Synchronized(writer);
+ }
+ }
// This class cannot be instantiated.
private Console() {}
@@ -74,18 +123,7 @@ public sealed class Console
{
get
{
- lock(typeof(Console))
- {
- if(stdin != null)
- {
- return stdin;
- }
- else
- {
- stdin = new
StdReader(0);
- return stdin;
- }
- }
+ return StdIn.stream;
}
}
@@ -94,27 +132,7 @@ public sealed class Console
{
get
{
- lock(typeof(Console))
- {
- if(stdout != null)
- {
- return stdout;
- }
- else
- {
- Encoding encoding =
Encoding.Default;
- if(encoding is
UTF8Encoding)
- {
- // Disable the
preamble if UTF-8.
- encoding = new
UTF8Encoding();
- }
- StreamWriter writer =
new StreamWriter
- (new
StdStream(1), encoding);
- writer.AutoFlush = true;
- SetOut(writer);
- return stdout;
- }
- }
+ return StdOut.stream;
}
}
@@ -123,27 +141,7 @@ public sealed class Console
{
get
{
- lock(typeof(Console))
- {
- if(stderr != null)
- {
- return stderr;
- }
- else
- {
- Encoding encoding =
Encoding.Default;
- if(encoding is
UTF8Encoding)
- {
- // Disable the
preamble if UTF-8.
- encoding = new
UTF8Encoding();
- }
- StreamWriter writer =
new StreamWriter
- (new
StdStream(2), encoding);
- writer.AutoFlush = true;
- SetError(writer);
- return stderr;
- }
- }
+ return StdErr.stream;
}
}
@@ -188,7 +186,7 @@ public sealed class Console
{
throw new
ArgumentNullException("newIn");
}
- stdin = TextReader.Synchronized(newIn);
+ StdIn.stream = TextReader.Synchronized(newIn);
}
// Set the standard output stream.
@@ -198,7 +196,7 @@ public sealed class Console
{
throw new
ArgumentNullException("newOut");
}
- stdout = TextWriter.Synchronized(newOut);
+ StdOut.stream = TextWriter.Synchronized(newOut);
}
// Set the standard error stream.
@@ -208,7 +206,7 @@ public sealed class Console
{
throw new
ArgumentNullException("newError");
}
- stderr = TextWriter.Synchronized(newError);
+ StdErr.stream =
TextWriter.Synchronized(newError);
}
// Read a character from the standard input stream.
http://git.savannah.gnu.org/cgit/pnetlib.git/commit/?id=3ecb2aa652054910677cd548b2ce50e7be9199b1
commit 3ecb2aa652054910677cd548b2ce50e7be9199b1
Author: Klaus Treichel <address@hidden>
Date: Mon Nov 23 09:00:13 2009 +0100
Create a new DefaultBinder if the cached version is null instead of
not null.
diff --git a/ChangeLog b/ChangeLog
index bb92d1f..4d3008b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2009-11-23 Klaus Treichel <address@hidden>
+ * runtime/System/Type.cs (DefaultBinder): Create a new DefaultBinder if
+ the cached version is null instead of not null.
+
* runtime/System/IO/TextReader.cs: Lock the underlying reader instead of
this in the synchronized text reader.
diff --git a/runtime/System/Type.cs b/runtime/System/Type.cs
index 8a09504..3050c6d 100644
--- a/runtime/System/Type.cs
+++ b/runtime/System/Type.cs
@@ -1406,7 +1406,7 @@ public abstract class Type
{
lock(typeof(Type))
{
- if(defaultBinder !=
null)
+ if(defaultBinder ==
null)
{
defaultBinder =
new DefaultBinder();
}
http://git.savannah.gnu.org/cgit/pnetlib.git/commit/?id=f590966fddad8466ea0139f8340e134a163fd2e3
commit f590966fddad8466ea0139f8340e134a163fd2e3
Author: Klaus Treichel <address@hidden>
Date: Mon Nov 23 08:53:32 2009 +0100
Lock the underlying reader or writer instead of this in the synchronized
TextReader and TextWriter classes.
diff --git a/ChangeLog b/ChangeLog
index b217ee8..bb92d1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-11-23 Klaus Treichel <address@hidden>
+
+ * runtime/System/IO/TextReader.cs: Lock the underlying reader instead of
+ this in the synchronized text reader.
+
+ * runtime/System/IO/TextWriter.cs: Lock the underlying writer instead of
+ this in the synchronized text writer.
+
2009-11-21 Klaus Treichel <address@hidden>
* runtime/System/Text/Encoding.cs (InvokeI18N): Move the static
invariant
diff --git a/runtime/System/IO/TextReader.cs b/runtime/System/IO/TextReader.cs
index cdd40b8..aaa1967 100644
--- a/runtime/System/IO/TextReader.cs
+++ b/runtime/System/IO/TextReader.cs
@@ -227,7 +227,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Close this text reader.
public override void Close()
{
- lock(this)
+ lock(reader)
{
reader.Close();
}
@@ -236,7 +236,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Dispose this text reader.
protected override void Dispose(bool disposing)
{
- lock(this)
+ lock(reader)
{
reader.Dispose(disposing);
}
@@ -245,7 +245,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Peek at the next character.
public override int Peek()
{
- lock(this)
+ lock(reader)
{
return reader.Peek();
}
@@ -254,7 +254,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Read the next character.
public override int Read()
{
- lock(this)
+ lock(reader)
{
return reader.Read();
}
@@ -263,7 +263,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Read a buffer of characters.
public override int Read(char[] buffer, int index, int count)
{
- lock(this)
+ lock(reader)
{
return reader.Read(buffer,
index, count);
}
@@ -272,7 +272,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Read a buffer of characters, and fill the entire block.
public override int ReadBlock(char[] buffer, int index, int
count)
{
- lock(this)
+ lock(reader)
{
return reader.ReadBlock(buffer,
index, count);
}
@@ -281,7 +281,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Read the next line from this reader.
public override String ReadLine()
{
- lock(this)
+ lock(reader)
{
return reader.ReadLine();
}
@@ -290,7 +290,7 @@ public abstract class TextReader : MarshalByRefObject,
IDisposable
// Read until the end of the stream.
public override String ReadToEnd()
{
- lock(this)
+ lock(reader)
{
return reader.ReadToEnd();
}
diff --git a/runtime/System/IO/TextWriter.cs b/runtime/System/IO/TextWriter.cs
index ec5f0c3..3ca1db0 100644
--- a/runtime/System/IO/TextWriter.cs
+++ b/runtime/System/IO/TextWriter.cs
@@ -368,7 +368,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Close this text writer.
public override void Close()
{
- lock(this)
+ lock(writer)
{
writer.Close();
}
@@ -377,7 +377,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Dispose this text writer.
protected override void Dispose(bool disposing)
{
- lock(this)
+ lock(writer)
{
writer.Dispose(disposing);
}
@@ -386,7 +386,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Flush the contents of the text writer.
public override void Flush()
{
- lock(this)
+ lock(writer)
{
writer.Flush();
}
@@ -395,14 +395,14 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Write a formatted string to this text writer.
public override void Write(String format, Object arg0)
{
- lock(this)
+ lock(writer)
{
writer.Write(format, arg0);
}
}
public override void Write(String format, Object arg0, Object
arg1)
{
- lock(this)
+ lock(writer)
{
writer.Write(format, arg0,
arg1);
}
@@ -410,14 +410,14 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
public override void Write(String format, Object arg0, Object
arg1,
Object arg2)
{
- lock(this)
+ lock(writer)
{
writer.Write(format, arg0,
arg1, arg2);
}
}
public override void Write(String format, params Object[] args)
{
- lock(this)
+ lock(writer)
{
writer.Write(format, args);
}
@@ -426,28 +426,28 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Write primitive values to this text writer.
public override void Write(bool value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(char value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(char[] value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(char[] value, int index, int count)
{
- lock(this)
+ lock(writer)
{
writer.Write(value, index,
count);
}
@@ -455,21 +455,21 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
#if CONFIG_EXTENDED_NUMERICS
public override void Write(double value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(Decimal value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(float value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
@@ -477,42 +477,42 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
#endif
public override void Write(int value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(uint value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(long value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(ulong value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(Object value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
}
public override void Write(String value)
{
- lock(this)
+ lock(writer)
{
writer.Write(value);
}
@@ -521,7 +521,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Write a newline to this text writer.
public override void WriteLine()
{
- lock(this)
+ lock(writer)
{
writer.WriteLine();
}
@@ -530,14 +530,14 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Write a formatted string to this text writer followed by a
newline.
public override void WriteLine(String format, Object arg0)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(format, arg0);
}
}
public override void WriteLine(String format, Object arg0,
Object arg1)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(format, arg0,
arg1);
}
@@ -545,14 +545,14 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
public override void WriteLine(String format, Object arg0,
Object arg1,
Object
arg2)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(format, arg0,
arg1, arg2);
}
}
public override void WriteLine(String format, params Object[]
args)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(format, args);
}
@@ -561,28 +561,28 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
// Write primitive values to this text writer followed by a
newline.
public override void WriteLine(bool value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(char value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(char[] value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(char[] value, int index, int
count)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value, index,
count);
}
@@ -590,21 +590,21 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
#if CONFIG_EXTENDED_NUMERICS
public override void WriteLine(double value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(Decimal value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(float value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
@@ -612,42 +612,42 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
#endif
public override void WriteLine(int value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(uint value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(long value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(ulong value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(Object value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
}
public override void WriteLine(String value)
{
- lock(this)
+ lock(writer)
{
writer.WriteLine(value);
}
@@ -659,7 +659,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
get
{
System.Text.Encoding enc;
- lock(this)
+ lock(writer)
{
enc = writer.Encoding;
}
@@ -673,7 +673,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
get
{
String nl;
- lock(this)
+ lock(writer)
{
nl = writer.NewLine;
}
@@ -681,7 +681,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
}
set
{
- lock(this)
+ lock(writer)
{
writer.NewLine = value;
}
@@ -694,7 +694,7 @@ public abstract class TextWriter : MarshalByRefObject,
IDisposable
get
{
IFormatProvider prov;
- lock(this)
+ lock(writer)
{
prov =
writer.FormatProvider;
}
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 16 +++++
runtime/System/Console.cs | 120 +++++++++++++++++++--------------------
runtime/System/IO/TextReader.cs | 16 +++---
runtime/System/IO/TextWriter.cs | 84 ++++++++++++++--------------
runtime/System/Type.cs | 2 +-
5 files changed, 126 insertions(+), 112 deletions(-)
hooks/post-receive
--
DotGNU Portable.NET Class Library (pnetlib)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET Class Library (pnetlib) branch, master, updated. 2dba8321b1d7110e25d57dd465aea9229a1865c1,
Klaus Treichel <=