From 9719e37cec64c4a3e2b31c1141dbdd5979f6d69c Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Fri, 23 Jan 2004 14:37:09 +0000 Subject: FileLockImpl.java: Fixed filename in copyright. 2004-01-23 Michael Koch * gnu/java/nio/FileLockImpl.java: Fixed filename in copyright. (released): Removed. (finalize): New method. * gnu/java/nio/natFileLockImpl.cc (releaseImpl): Implemented. * java/nio/channels/FileChannelImpl.java: Reworked imports. (lock): Implemented. (lockImpl): New method. (tryLock): Implemented. (tryLockImpl): New method. * java/nio/channels/natFileChannelImpl.cc (lockImpl): New method. (tryLockImpl): New method. From-SVN: r76422 --- libjava/java/nio/channels/FileChannelImpl.java | 41 ++++++++++++++++++++++--- libjava/java/nio/channels/natFileChannelImpl.cc | 16 ++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) (limited to 'libjava/java/nio') diff --git a/libjava/java/nio/channels/FileChannelImpl.java b/libjava/java/nio/channels/FileChannelImpl.java index 89ac11a..ea2526e 100644 --- a/libjava/java/nio/channels/FileChannelImpl.java +++ b/libjava/java/nio/channels/FileChannelImpl.java @@ -38,6 +38,9 @@ exception statement from your version. */ package java.nio.channels; +import gnu.classpath.Configuration; +import gnu.gcj.RawData; +import gnu.java.nio.FileLockImpl; import java.io.EOFException; import java.io.FileDescriptor; import java.io.FileInputStream; @@ -47,8 +50,6 @@ import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.MappedByteBufferImpl; -import gnu.classpath.Configuration; -import gnu.gcj.RawData; /** * This file is not user visible ! @@ -354,8 +355,22 @@ public class FileChannelImpl extends FileChannel file_obj instanceof FileInputStream) throw new NonWritableChannelException (); - throw new Error ("Not implemented"); + boolean completed = false; + + try + { + begin(); + lockImpl(position, size, shared); + completed = true; + return new FileLockImpl(fd, this, position, size, shared); + } + finally + { + end(completed); + } } + + private native void lockImpl(long position, long size, boolean shared); public FileLock tryLock (long position, long size, boolean shared) throws IOException @@ -367,9 +382,27 @@ public class FileChannelImpl extends FileChannel if (!isOpen ()) throw new ClosedChannelException (); - throw new Error ("Not implemented"); + if (! tryLockImpl(position, size, shared)) + return null; + + boolean completed = false; + + try + { + boolean lockable = tryLockImpl(position, size, shared); + completed = true; + return (lockable + ? new FileLockImpl(fd, this, position, size, shared) + : null); + } + finally + { + end(completed); + } } + private native boolean tryLockImpl(long position, long size, boolean shared); + public long position () throws IOException { diff --git a/libjava/java/nio/channels/natFileChannelImpl.cc b/libjava/java/nio/channels/natFileChannelImpl.cc index 8dbbd14..56828a4 100644 --- a/libjava/java/nio/channels/natFileChannelImpl.cc +++ b/libjava/java/nio/channels/natFileChannelImpl.cc @@ -25,11 +25,13 @@ details. */ #endif #include +#include #include #include #include #include #include +#include jlong java::nio::channels::FileChannelImpl::size () @@ -92,3 +94,17 @@ java::nio::channels::FileChannelImpl::nio_msync (gnu::gcj::RawData* /*map_addres { throw new ::java::io::IOException (JvNewStringUTF ("msync not implemented")); } + +void +java::nio::channels::FileChannelImpl::lockImpl(jlong position, jlong size, jboolean shared) +{ + // FIXME: shared is unused, write is always true. + fd->lock(position, size, true); +} + +jboolean +java::nio::channels::FileChannelImpl::tryLockImpl(jlong position, jlong size, jboolean shared) +{ + // FIXME: shared is unused, write is always true. + return fd->tryLock(position, size, true); +} -- cgit v1.1