Skip to content

Commit

Permalink
Avoid using WeakSafeReadWriteLock when not using weak references
Browse files Browse the repository at this point in the history
This avoids needing to create a wrapper object every time we attain the lock.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173310332
  • Loading branch information
michajlo authored and cpovirk committed Oct 25, 2017
1 parent b72fe86 commit 3d90141
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,18 @@ public static Striped<ReadWriteLock> readWriteLock(int stripes) {
* @return a new {@code Striped<ReadWriteLock>}
*/
public static Striped<ReadWriteLock> lazyWeakReadWriteLock(int stripes) {
return lazy(stripes, READ_WRITE_LOCK_SUPPLIER);
return lazy(stripes, WEAK_SAFE_READ_WRITE_LOCK_SUPPLIER);
}

private static final Supplier<ReadWriteLock> READ_WRITE_LOCK_SUPPLIER =
new Supplier<ReadWriteLock>() {
@Override
public ReadWriteLock get() {
return new ReentrantReadWriteLock();
}
};

private static final Supplier<ReadWriteLock> WEAK_SAFE_READ_WRITE_LOCK_SUPPLIER =
new Supplier<ReadWriteLock>() {
@Override
public ReadWriteLock get() {
Expand Down
10 changes: 9 additions & 1 deletion guava/src/com/google/common/util/concurrent/Striped.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,18 @@ public static Striped<ReadWriteLock> readWriteLock(int stripes) {
* @return a new {@code Striped<ReadWriteLock>}
*/
public static Striped<ReadWriteLock> lazyWeakReadWriteLock(int stripes) {
return lazy(stripes, READ_WRITE_LOCK_SUPPLIER);
return lazy(stripes, WEAK_SAFE_READ_WRITE_LOCK_SUPPLIER);
}

private static final Supplier<ReadWriteLock> READ_WRITE_LOCK_SUPPLIER =
new Supplier<ReadWriteLock>() {
@Override
public ReadWriteLock get() {
return new ReentrantReadWriteLock();
}
};

private static final Supplier<ReadWriteLock> WEAK_SAFE_READ_WRITE_LOCK_SUPPLIER =
new Supplier<ReadWriteLock>() {
@Override
public ReadWriteLock get() {
Expand Down

0 comments on commit 3d90141

Please sign in to comment.