jdk/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java
changeset 32865 f9cb6e427f9e
parent 30462 507bcb03c954
child 34790 9c21084e8cb9
equal deleted inserted replaced
32864:2a338536e642 32865:f9cb6e427f9e
  1298      * started.
  1298      * started.
  1299      *
  1299      *
  1300      * @return the thread actively modifying the document
  1300      * @return the thread actively modifying the document
  1301      *  or <code>null</code> if there are no modifications in progress
  1301      *  or <code>null</code> if there are no modifications in progress
  1302      */
  1302      */
  1303     protected synchronized final Thread getCurrentWriter() {
  1303     protected final synchronized Thread getCurrentWriter() {
  1304         return currWriter;
  1304         return currWriter;
  1305     }
  1305     }
  1306 
  1306 
  1307     /**
  1307     /**
  1308      * Acquires a lock to begin mutating the document this lock
  1308      * Acquires a lock to begin mutating the document this lock
  1327      *  only happen if a document listener attempts to mutate the
  1327      *  only happen if a document listener attempts to mutate the
  1328      *  document.  This situation violates the bean event model
  1328      *  document.  This situation violates the bean event model
  1329      *  where order of delivery is not guaranteed and all listeners
  1329      *  where order of delivery is not guaranteed and all listeners
  1330      *  should be notified before further mutations are allowed.
  1330      *  should be notified before further mutations are allowed.
  1331      */
  1331      */
  1332     protected synchronized final void writeLock() {
  1332     protected final synchronized void writeLock() {
  1333         try {
  1333         try {
  1334             while ((numReaders > 0) || (currWriter != null)) {
  1334             while ((numReaders > 0) || (currWriter != null)) {
  1335                 if (Thread.currentThread() == currWriter) {
  1335                 if (Thread.currentThread() == currWriter) {
  1336                     if (notifyingListeners) {
  1336                     if (notifyingListeners) {
  1337                         // Assuming one doesn't do something wrong in a
  1337                         // Assuming one doesn't do something wrong in a
  1357      * After decrementing the lock count if there are no outstanding locks
  1357      * After decrementing the lock count if there are no outstanding locks
  1358      * this will allow a new writer, or readers.
  1358      * this will allow a new writer, or readers.
  1359      *
  1359      *
  1360      * @see #writeLock
  1360      * @see #writeLock
  1361      */
  1361      */
  1362     protected synchronized final void writeUnlock() {
  1362     protected final synchronized void writeUnlock() {
  1363         if (--numWriters <= 0) {
  1363         if (--numWriters <= 0) {
  1364             numWriters = 0;
  1364             numWriters = 0;
  1365             currWriter = null;
  1365             currWriter = null;
  1366             notifyAll();
  1366             notifyAll();
  1367         }
  1367         }
  1376      * of the document.  It should always be balanced with a
  1376      * of the document.  It should always be balanced with a
  1377      * <code>readUnlock</code>.
  1377      * <code>readUnlock</code>.
  1378      *
  1378      *
  1379      * @see #readUnlock
  1379      * @see #readUnlock
  1380      */
  1380      */
  1381     public synchronized final void readLock() {
  1381     public final synchronized void readLock() {
  1382         try {
  1382         try {
  1383             while (currWriter != null) {
  1383             while (currWriter != null) {
  1384                 if (currWriter == Thread.currentThread()) {
  1384                 if (currWriter == Thread.currentThread()) {
  1385                     // writer has full read access.... may try to acquire
  1385                     // writer has full read access.... may try to acquire
  1386                     // lock in notification
  1386                     // lock in notification
  1410      * &nbsp;   }
  1410      * &nbsp;   }
  1411      * </code></pre>
  1411      * </code></pre>
  1412      *
  1412      *
  1413      * @see #readLock
  1413      * @see #readLock
  1414      */
  1414      */
  1415     public synchronized final void readUnlock() {
  1415     public final synchronized void readUnlock() {
  1416         if (currWriter == Thread.currentThread()) {
  1416         if (currWriter == Thread.currentThread()) {
  1417             // writer has full read access.... may try to acquire
  1417             // writer has full read access.... may try to acquire
  1418             // lock in notification
  1418             // lock in notification
  1419             return;
  1419             return;
  1420         }
  1420         }