* java/io/PipedReader: Synchronize on "lock" instead of this.
From-SVN: r38731
This commit is contained in:
parent
75b7557d49
commit
a7fabf19be
2 changed files with 130 additions and 114 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2001-01-06 Bryce McKinlay <bryce@albatross.co.nz>
|
||||||
|
|
||||||
|
* java/io/PipedReader: Synchronize on "lock" instead of this.
|
||||||
|
|
||||||
2001-01-05 Bryce McKinlay <bryce@albatross.co.nz>
|
2001-01-05 Bryce McKinlay <bryce@albatross.co.nz>
|
||||||
|
|
||||||
* java/lang/Thread.java: Update comment.
|
* java/lang/Thread.java: Update comment.
|
||||||
|
@ -6,7 +10,7 @@
|
||||||
* java/io/PipedOutputStream: Updated to match new PipedInputStream.
|
* java/io/PipedOutputStream: Updated to match new PipedInputStream.
|
||||||
* java/io/PipedReader: New implementation based on new
|
* java/io/PipedReader: New implementation based on new
|
||||||
PipedInputStream.
|
PipedInputStream.
|
||||||
* java/io/PipedWriter: Updated to match new PipedOutputStream.
|
* java/io/PipedWriter: Updated to match new PipedReader.
|
||||||
|
|
||||||
2001-01-03 Tom Tromey <tromey@redhat.com>
|
2001-01-03 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
|
|
@ -141,8 +141,10 @@ public class PipedReader extends Reader
|
||||||
* put it here in order to support that bizarre recieve(int)
|
* put it here in order to support that bizarre recieve(int)
|
||||||
* method.
|
* method.
|
||||||
*/
|
*/
|
||||||
synchronized void receive(char[] buf, int offset, int len)
|
void receive(char[] buf, int offset, int len)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
{
|
||||||
|
synchronized (lock)
|
||||||
{
|
{
|
||||||
if (closed)
|
if (closed)
|
||||||
throw new IOException ("Pipe closed");
|
throw new IOException ("Pipe closed");
|
||||||
|
@ -157,8 +159,8 @@ public class PipedReader extends Reader
|
||||||
while (in == out)
|
while (in == out)
|
||||||
{
|
{
|
||||||
// The pipe is full. Wake up any readers and wait for them.
|
// The pipe is full. Wake up any readers and wait for them.
|
||||||
notifyAll();
|
lock.notifyAll();
|
||||||
wait();
|
lock.wait();
|
||||||
// The pipe could have been closed while we were waiting.
|
// The pipe could have been closed while we were waiting.
|
||||||
if (closed)
|
if (closed)
|
||||||
throw new IOException ("Pipe closed");
|
throw new IOException ("Pipe closed");
|
||||||
|
@ -188,7 +190,8 @@ public class PipedReader extends Reader
|
||||||
in = 0;
|
in = 0;
|
||||||
}
|
}
|
||||||
// Notify readers that new data is in the pipe.
|
// Notify readers that new data is in the pipe.
|
||||||
notifyAll();
|
lock.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,8 +243,10 @@ public class PipedReader extends Reader
|
||||||
* @exception IOException If <code>close()/code> was called on this Piped
|
* @exception IOException If <code>close()/code> was called on this Piped
|
||||||
* Reader.
|
* Reader.
|
||||||
*/
|
*/
|
||||||
public synchronized int read(char[] buf, int offset, int len)
|
public int read(char[] buf, int offset, int len)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
{
|
||||||
|
synchronized (lock)
|
||||||
{
|
{
|
||||||
if (source == null)
|
if (source == null)
|
||||||
throw new IOException ("Not connected");
|
throw new IOException ("Not connected");
|
||||||
|
@ -256,7 +261,7 @@ public class PipedReader extends Reader
|
||||||
{
|
{
|
||||||
if (source.closed)
|
if (source.closed)
|
||||||
return -1;
|
return -1;
|
||||||
wait();
|
lock.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException ix)
|
catch (InterruptedException ix)
|
||||||
|
@ -297,17 +302,20 @@ public class PipedReader extends Reader
|
||||||
{
|
{
|
||||||
// Notify any waiting Writer that there is now space
|
// Notify any waiting Writer that there is now space
|
||||||
// to write.
|
// to write.
|
||||||
notifyAll();
|
lock.notifyAll();
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized boolean ready() throws IOException
|
public boolean ready() throws IOException
|
||||||
{
|
{
|
||||||
// The JDK 1.3 implementation does not appear to check for the closed or
|
// The JDK 1.3 implementation does not appear to check for the closed or
|
||||||
// unconnected stream conditions here.
|
// unconnected stream conditions here.
|
||||||
|
|
||||||
|
synchronized (lock)
|
||||||
|
{
|
||||||
if (in < 0)
|
if (in < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -319,6 +327,7 @@ public class PipedReader extends Reader
|
||||||
|
|
||||||
return (count > 0);
|
return (count > 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This methods closes the stream so that no more data can be read
|
* This methods closes the stream so that no more data can be read
|
||||||
|
@ -326,10 +335,13 @@ public class PipedReader extends Reader
|
||||||
*
|
*
|
||||||
* @exception IOException If an error occurs
|
* @exception IOException If an error occurs
|
||||||
*/
|
*/
|
||||||
public synchronized void close() throws IOException
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
synchronized (lock)
|
||||||
{
|
{
|
||||||
closed = true;
|
closed = true;
|
||||||
// Wake any thread which may be in receive() waiting to write data.
|
// Wake any thread which may be in receive() waiting to write data.
|
||||||
notifyAll();
|
lock.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue