FileLockImpl.java: Fixed filename in copyright.
authorMichael Koch <konqueror@gmx.de>
Fri, 23 Jan 2004 14:37:09 +0000 (14:37 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Fri, 23 Jan 2004 14:37:09 +0000 (14:37 +0000)
2004-01-23  Michael Koch  <konqueror@gmx.de>

* 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/ChangeLog
libjava/gnu/java/nio/FileLockImpl.java
libjava/gnu/java/nio/natFileLockImpl.cc
libjava/java/nio/channels/FileChannelImpl.java
libjava/java/nio/channels/natFileChannelImpl.cc

index 1d25820785f81599eaa8d91af26701cbcd4045cb..578a308d8dab84a77b1abb58e9316e4f8943fde8 100644 (file)
@@ -1,3 +1,21 @@
+2004-01-23  Michael Koch  <konqueror@gmx.de>
+
+       * 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.
+
 2004-01-23  Michael Koch  <konqueror@gmx.de>
 
        * java/io/FileDescriptor.java
index f85d60ad67f02226ff326537f2ffe07f49cc6283..b621bd2a539ba66308e649b5bfc04ea3f4c1675e 100644 (file)
@@ -1,5 +1,5 @@
-/* FileChannelImpl.java -- 
-   Copyright (C) 2002 Free Software Foundation, Inc.
+/* FileLockImpl.java -- 
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -60,14 +60,24 @@ public class FileLockImpl extends FileLock
   }
   
   private FileDescriptor fd;
-  private boolean released;
   
   public FileLockImpl (FileDescriptor fd, FileChannel channel, long position,
                        long size, boolean shared)
   {
     super (channel, position, size, shared);
     this.fd = fd;
-    this.released = false;
+  }
+
+  public void finalize()
+  {
+    try
+      {
+       release();
+      }
+    catch (IOException e)
+      {
+       // Ignore this.
+      }
   }
   
   public boolean isValid ()
index 19a3b83fde75b78a875c4c74da5a82e3b3898c54..d3d01a12df3261ac426427eca01ad1169a4d9bd3 100644 (file)
@@ -20,6 +20,5 @@ details.  */
 void
 gnu::java::nio::FileLockImpl::releaseImpl ()
 {
-  throw new ::java::io::IOException
-    (JvNewStringUTF ("releaseImpl not implemented"));
+  fd->unlock(position(), size());
 }
index 89ac11ad514b38b7ba1ba64571d9fff242fd6b7b..ea2526e7002f6c80564a419b64a0e45ece7ae1e1 100644 (file)
@@ -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
   {
index 8dbbd141e604625c81bf6766f1bb9be038b084b2..56828a46604c1da25c6354f80501a387cb16dd81 100644 (file)
@@ -25,11 +25,13 @@ details.  */
 #endif
 
 #include <gnu/gcj/RawData.h>
+#include <gnu/java/nio/FileLockImpl.h>
 #include <java/io/FileDescriptor.h>
 #include <java/io/IOException.h>
 #include <java/nio/ByteBuffer.h>
 #include <java/nio/channels/FileChannel.h>
 #include <java/nio/channels/FileChannelImpl.h>
+#include <java/nio/channels/FileLock.h>
 
 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);
+}