[hg] main-silver: #232210: synchronizing the access to the curre...

  • From: Jan Lahoda < >
  • To: ,
  • Subject: [hg] main-silver: #232210: synchronizing the access to the curre...
  • Date: Thu, 18 Jul 2013 15:52:42 -0700

changeset 3e6229cab112 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/3e6229cab112
description:
        #232210: synchronizing the access to the currentBlock field, as the 
MarkBlockChain can be access from multiple threads (otherwise would required 
a write/exclusive lock from the caller, but that is impossible for some 
callers).

diffstat:

 editor.lib/src/org/netbeans/editor/MarkBlockChain.java |  14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diffs (73 lines):

diff --git a/editor.lib/src/org/netbeans/editor/MarkBlockChain.java 
b/editor.lib/src/org/netbeans/editor/MarkBlockChain.java
--- a/editor.lib/src/org/netbeans/editor/MarkBlockChain.java
+++ b/editor.lib/src/org/netbeans/editor/MarkBlockChain.java
@@ -94,7 +94,7 @@
     *   as startPos when insert is made
     * @return relation of currentBlock to the given block
     */
-    public int compareBlock(int startPos, int endPos) {
+    public synchronized int compareBlock(int startPos, int endPos) {
         if (currentBlock == null) {
             currentBlock = chain;
             if (currentBlock == null) {
@@ -219,7 +219,7 @@
     /** Add non-empty block to the chain of blocks
     * @param concat whether concatenate adjacent blocks
     */
-    public void addBlock(int startPos, int endPos, boolean concat) {
+    public synchronized void addBlock(int startPos, int endPos, boolean 
concat) {
         if (startPos == endPos) {
             return;
         }
@@ -280,6 +280,7 @@
             return;
         }
         try {
+            synchronized (this) {
             int rel;
             while (((rel = compareBlock(startPos, endPos)) & 
MarkBlock.OVERLAP) != 0) {
                 if ((rel & MarkBlock.THIS_EMPTY) != 0) { // currentBlock is 
empty
@@ -305,6 +306,7 @@
                     }
                 }
             }
+            }
             PCS.firePropertyChange(PROP_BLOCKS_CHANGED, startPos, endPos);
         } catch (BadLocationException e) {
             Utilities.annotateLoggable(e);
@@ -316,7 +318,7 @@
     /** Removes mark block and possibly updates the chain.
     * @return next block after removed one
     */
-    protected MarkBlock checkedRemove(MarkBlock blk) {
+    protected synchronized MarkBlock checkedRemove(MarkBlock blk) {
         boolean first = (blk == chain);
         blk = blk.removeChain();
         if (first) {
@@ -326,7 +328,7 @@
         return blk;
     }
 
-    public int adjustToBlockEnd(int pos) {
+    public synchronized int adjustToBlockEnd(int pos) {
         int rel = compareBlock(pos, pos) & MarkBlock.IGNORE_EMPTY;
         if (rel == MarkBlock.INSIDE_BEGIN || rel == MarkBlock.INNER) { // 
inside blk
             pos = currentBlock.getEndOffset();
@@ -336,7 +338,7 @@
 
     /** Return the position adjusted to the start of the next mark-block.
     */
-    public int adjustToNextBlockStart(int pos) {
+    public synchronized int adjustToNextBlockStart(int pos) {
         // !!! what about empty blocks
         int rel = compareBlock(pos, pos) & MarkBlock.IGNORE_EMPTY;
         if ((rel & MarkBlock.BEFORE) != 0) {
@@ -356,7 +358,7 @@
         return pos;
     }
 
-    public @Override String toString() {
+    public synchronized @Override String toString() {
         return "MarkBlockChain: currentBlock=" + currentBlock + "\nblock 
chain: " // NOI18N
                + (chain != null ? ("\n" + chain.toStringChain()) : " 
Empty"); // NOI18N
     }

[hg] main-silver: #232210: synchronizing the access to the curre...

Jan Lahoda 07/18/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close