IGNITE-22989 Add sync/async read-write lock#4233
Conversation
modules/core/src/main/java/org/apache/ignite/internal/util/VersatileReadWriteLock.java
Outdated
Show resolved
Hide resolved
| * read lock are waiting for write lock to be released, a write lock attempt will be served first when the release happens). | ||
| */ | ||
| @SuppressWarnings("unused") | ||
| private volatile int pendingWriteLocks; |
There was a problem hiding this comment.
Why not making both parts a single long value?
There was a problem hiding this comment.
Are you asking about state and pendingWriteChecks? They don't always get CASed together, so I don't see why we would want to merge them together.
There was a problem hiding this comment.
They're on a single cache line anyway, so there's already a naturally occurring contention
There was a problem hiding this comment.
If they are in the same long, they are guaranteed to be on the same cache line; if they aren't, maybe they will be in different cache lines (this is possible at least in theory, right?). So no gain here, maybe even a loss.
Also, squashing them together complicates the code, which is also a loss.
I see no gain from squashing, only losses.
modules/core/src/main/java/org/apache/ignite/internal/util/VersatileReadWriteLock.java
Outdated
Show resolved
Hide resolved
modules/core/src/test/java/org/apache/ignite/internal/util/VersatileReadWriteLockTest.java
Outdated
Show resolved
Hide resolved
| CompletableFuture<?> future = runAsync(() -> { | ||
| lock.readLock(); | ||
| lock.readUnlock(); | ||
| }); | ||
| future.get(10, SECONDS); | ||
| }, executor); | ||
| assertThat(future, willCompleteSuccessfully()); |
There was a problem hiding this comment.
runWithTimeout does the same, is that correct? That's why I don't like on-liner methods, you just forget that you could use them
There was a problem hiding this comment.
Same logic, but different type of a closure
https://issues.apache.org/jira/browse/IGNITE-22989