< prev index next >

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java

Print this page
@@ -76,10 +76,11 @@
      private final FileDescriptor fd;
  
      // File access mode (immutable)
      private final boolean writable;
      private final boolean readable;
+     private final boolean sync;  // O_SYNC or O_DSYNC
  
      // Required to prevent finalization of creating stream (immutable)
      private final Closeable parent;
  
      // The path of the referenced file

@@ -120,16 +121,18 @@
              }
          }
      }
  
      private FileChannelImpl(FileDescriptor fd, String path, boolean readable,
-                             boolean writable, boolean direct, Closeable parent)
+                             boolean writable, boolean sync, boolean direct,
+                             Closeable parent)
      {
          this.fd = fd;
          this.path = path;
          this.readable = readable;
          this.writable = writable;
+         this.sync = sync;
          this.direct = direct;
          this.parent = parent;
          if (direct) {
              assert path != null;
              this.alignment = nd.setDirectIO(fd, path);

@@ -148,13 +151,13 @@
  
      // Used by FileInputStream::getChannel, FileOutputStream::getChannel,
      // and RandomAccessFile::getChannel
      public static FileChannel open(FileDescriptor fd, String path,
                                     boolean readable, boolean writable,
-                                    boolean direct, Closeable parent)
+                                    boolean sync, boolean direct, Closeable parent)
      {
-         return new FileChannelImpl(fd, path, readable, writable, direct, parent);
+         return new FileChannelImpl(fd, path, readable, writable, sync, direct, parent);
      }
  
      private void ensureOpen() throws IOException {
          if (!isOpen())
              throw new ClosedChannelException();

@@ -228,15 +231,15 @@
                  beginBlocking();
                  ti = threads.add();
                  if (!isOpen())
                      return 0;
                  do {
-                     long comp = Blocker.begin();
+                     boolean attempted = Blocker.beginCompenstate(direct);
                      try {
                          n = IOUtil.read(fd, dst, -1, direct, alignment, nd);
                      } finally {
-                         Blocker.end(comp);
+                         Blocker.endCompenstate(attempted);
                      }
                  } while ((n == IOStatus.INTERRUPTED) && isOpen());
                  return IOStatus.normalize(n);
              } finally {
                  threads.remove(ti);

@@ -263,15 +266,15 @@
                  beginBlocking();
                  ti = threads.add();
                  if (!isOpen())
                      return 0;
                  do {
-                     long comp = Blocker.begin();
+                     boolean attempted = Blocker.beginCompenstate(direct);
                      try {
                          n = IOUtil.read(fd, dsts, offset, length, direct, alignment, nd);
                      } finally {
-                         Blocker.end(comp);
+                         Blocker.endCompenstate(attempted);
                      }
  
                  } while ((n == IOStatus.INTERRUPTED) && isOpen());
                  return IOStatus.normalize(n);
              } finally {

@@ -296,15 +299,15 @@
                  beginBlocking();
                  ti = threads.add();
                  if (!isOpen())
                      return 0;
                  do {
-                     long comp = Blocker.begin();
+                     boolean attempted = Blocker.beginCompenstate(sync | direct);
                      try {
                          n = IOUtil.write(fd, src, -1, direct, alignment, nd);
                      } finally {
-                         Blocker.end(comp);
+                         Blocker.endCompenstate(attempted);
                      }
  
                  } while ((n == IOStatus.INTERRUPTED) && isOpen());
                  return IOStatus.normalize(n);
              } finally {

@@ -332,15 +335,15 @@
                  beginBlocking();
                  ti = threads.add();
                  if (!isOpen())
                      return 0;
                  do {
-                     long comp = Blocker.begin();
+                     boolean attempted = Blocker.beginCompenstate(sync | direct);
                      try {
                          n = IOUtil.write(fd, srcs, offset, length, direct, alignment, nd);
                      } finally {
-                         Blocker.end(comp);
+                         Blocker.endCompenstate(attempted);
                      }
                  } while ((n == IOStatus.INTERRUPTED) && isOpen());
                  return IOStatus.normalize(n);
              } finally {
                  threads.remove(ti);

@@ -527,15 +530,15 @@
              beginBlocking();
              ti = threads.add();
              if (!isOpen())
                  return;
              do {
-                 long comp = Blocker.begin();
+                 boolean attempted = Blocker.beginCompenstate();
                  try {
                      rv = nd.force(fd, metaData);
                  } finally {
-                     Blocker.end(comp);
+                     Blocker.endCompenstate(attempted);
                  }
              } while ((rv == IOStatus.INTERRUPTED) && isOpen());
          } finally {
              threads.remove(ti);
              endBlocking(rv > -1);

@@ -1086,15 +1089,15 @@
              beginBlocking();
              ti = threads.add();
              if (!isOpen())
                  return -1;
              do {
-                 long comp = Blocker.begin();
+                 boolean attempted = Blocker.beginCompenstate(direct);
                  try {
                      n = IOUtil.read(fd, dst, position, direct, alignment, nd);
                  } finally {
-                     Blocker.end(comp);
+                     Blocker.endCompenstate(attempted);
                  }
              } while ((n == IOStatus.INTERRUPTED) && isOpen());
              return IOStatus.normalize(n);
          } finally {
              threads.remove(ti);

@@ -1131,15 +1134,15 @@
              beginBlocking();
              ti = threads.add();
              if (!isOpen())
                  return -1;
              do {
-                 long comp = Blocker.begin();
+                 boolean attempted = Blocker.beginCompenstate(sync | direct);
                  try {
                      n = IOUtil.write(fd, src, position, direct, alignment, nd);
                  } finally {
-                     Blocker.end(comp);
+                     Blocker.endCompenstate(attempted);
                  }
              } while ((n == IOStatus.INTERRUPTED) && isOpen());
              return IOStatus.normalize(n);
          } finally {
              threads.remove(ti);

@@ -1573,15 +1576,15 @@
              ti = threads.add();
              if (!isOpen())
                  return null;
              int n;
              do {
-                 long comp = Blocker.begin();
+                 boolean attempted = Blocker.beginCompenstate();
                  try {
                      n = nd.lock(fd, true, position, size, shared);
                  } finally {
-                     Blocker.end(comp);
+                     Blocker.endCompenstate(attempted);
                  }
              } while ((n == FileDispatcher.INTERRUPTED) && isOpen());
              if (isOpen()) {
                  if (n == FileDispatcher.RET_EX_LOCK) {
                      assert shared;
< prev index next >