rpuch commented on a change in pull request #414:
URL: https://github.com/apache/ignite-3/pull/414#discussion_r738120382



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/IgniteSpinReadWriteLock.java
##########
@@ -303,42 +375,32 @@ public boolean tryWriteLock() {
     }
 
     /**
+     * Tries to acquire the write lock with timeout. If it gets the write lock 
before the timeout expires, then
+     * returns {@code true}. If the timeout expires before the lock becomes 
available, returns {@code false}.
+     *
      * @param timeout Timeout.
      * @param unit Unit.
-     * @return {@code True} if write lock has been acquired.
+     * @return {@code true} if write lock has been acquired in time; {@code 
false} otherwise
      * @throws InterruptedException If interrupted.
      */
     @SuppressWarnings("BusyWait")
     public boolean tryWriteLock(long timeout, TimeUnit unit) throws 
InterruptedException {
-        long threadId = Thread.currentThread().getId();
-
-        if (threadId == writeLockOwner) {
-            assert state == -1;
-
-            writeLockEntryCnt++;
+        if (writeLockedByCurrentThread()) {
+            incrementWriteLockCount();
 
             return true;
         }
 
+        incrementPendingWriteLocks();
         try {
-            // Increment pending write locks.
-            while (true) {
-                int pendingWLocks0 = pendingWLocks;
-
-                if (compareAndSet(PENDING_WLOCKS_OFFS, pendingWLocks0, 
pendingWLocks0 + 1))
-                    break;
-            }
 

Review comment:
       Removed the blank line

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/IgniteSpinReadWriteLock.java
##########
@@ -172,101 +244,107 @@ public void readUnlock() {
     }
 
     /**
-     * Acquires write lock.
+     * Acquires write lock waiting, if needed. The thread will block until all 
other threads release both read
+     * and write locks.
      */
     @SuppressWarnings("BusyWait")
     public void writeLock() {
-        long threadId = Thread.currentThread().getId();
-
-        if (threadId == writeLockOwner) {
-            assert state == -1;
-
-            writeLockEntryCnt++;
+        if (writeLockedByCurrentThread()) {
+            incrementWriteLockCount();
 
             return;
         }
 
-        // Increment pending write locks.
-        while (true) {
-            int pendingWLocks0 = pendingWLocks;
-
-            if (compareAndSet(PENDING_WLOCKS_OFFS, pendingWLocks0, 
pendingWLocks0 + 1))
-                break;
-        }
-
         boolean interrupted = false;
 
-        while (!compareAndSet(STATE_OFFS, 0, -1)) {
-            try {
-                Thread.sleep(10);
-            }
-            catch (InterruptedException ignored) {
-                interrupted = true;
+        incrementPendingWriteLocks();
+        try {
+            while (!trySwitchStateToWriteLocked()) {
+                try {
+                    Thread.sleep(10);

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to