Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package javasabr.rlib.common.concurrent;

import java.util.concurrent.ThreadFactory;
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;
import org.jspecify.annotations.NullMarked;

/**
Expand All @@ -18,7 +18,7 @@ public interface ThreadConstructor {
Thread create(ThreadGroup group, Runnable runnable, String name);
}

private final ReusableAtomicInteger ordinal;
private final AtomicInteger ordinal;
private final String name;
private final ThreadGroup group;
private final ThreadConstructor constructor;
Expand All @@ -43,7 +43,7 @@ public GroupThreadFactory(String name, ThreadConstructor constructor, int priori
this.priority = priority;
this.name = name;
this.group = new ThreadGroup(name);
this.ordinal = new ReusableAtomicInteger();
this.ordinal = new AtomicInteger();
this.daemon = daemon;
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package javasabr.rlib.common.concurrent.lock.impl;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
import org.jspecify.annotations.NullMarked;

/**
Expand All @@ -20,7 +20,7 @@ public class AtomicLock implements Lock {
/**
* The status of lock.
*/
protected final ReusableAtomicInteger status;
protected final AtomicInteger status;

/**
* The field for consuming CPU.
Expand All @@ -31,7 +31,7 @@ public class AtomicLock implements Lock {
* Instantiates a new Atomic lock.
*/
public AtomicLock() {
this.status = new ReusableAtomicInteger();
this.status = new AtomicInteger();
this.sink = 1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package javasabr.rlib.common.concurrent.lock.impl;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
import javasabr.rlib.common.concurrent.lock.AsyncReadSyncWriteLock;
import org.jspecify.annotations.NullMarked;

Expand All @@ -25,17 +25,17 @@ public class AtomicReadWriteLock implements AsyncReadSyncWriteLock, Lock {
/**
* The status of write lock.
*/
protected final ReusableAtomicInteger writeStatus;
protected final AtomicInteger writeStatus;

/**
* The count of writers.
*/
protected final ReusableAtomicInteger writeCount;
protected final AtomicInteger writeCount;

/**
* The count of readers.
*/
protected final ReusableAtomicInteger readCount;
protected final AtomicInteger readCount;

/**
* The field for consuming CPU.
Expand All @@ -46,9 +46,9 @@ public class AtomicReadWriteLock implements AsyncReadSyncWriteLock, Lock {
* Instantiates a new Atomic read write lock.
*/
public AtomicReadWriteLock() {
this.writeCount = new ReusableAtomicInteger(0);
this.writeStatus = new ReusableAtomicInteger(0);
this.readCount = new ReusableAtomicInteger(0);
this.writeCount = new AtomicInteger(0);
this.writeStatus = new AtomicInteger(0);
this.readCount = new AtomicInteger(0);
this.sink = 1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package javasabr.rlib.common.concurrent.lock.impl;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicReference;
import org.jspecify.annotations.NullMarked;

/**
Expand All @@ -18,12 +18,12 @@ public class ReentrantAtomicLock implements Lock {
/**
* The status of lock.
*/
private final ReusableAtomicReference<Thread> status;
private final AtomicReference<Thread> status;

/**
* The level of locking.
*/
private final ReusableAtomicInteger level;
private final AtomicInteger level;

/**
* The field for consuming CPU.
Expand All @@ -34,8 +34,8 @@ public class ReentrantAtomicLock implements Lock {
* Instantiates a new Reentrant atomic lock.
*/
public ReentrantAtomicLock() {
this.status = new ReusableAtomicReference<>();
this.level = new ReusableAtomicInteger();
this.status = new AtomicReference<>();
this.level = new AtomicInteger();
this.sink = 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.function.Function;
import javasabr.rlib.common.concurrent.lock.Lockable;
import javasabr.rlib.common.function.ObjectIntFunction;
import javasabr.rlib.common.function.ObjectLongFunction;
import javasabr.rlib.logger.api.Logger;
import javasabr.rlib.logger.api.LoggerManager;
import org.jspecify.annotations.NullMarked;
Expand Down Expand Up @@ -148,26 +147,6 @@ public static <T extends Lockable, R> R get(T sync, int argument, ObjectIntFunct
}
}

/**
* Apply a function in locked block.
*
* @param <T> the type parameter
* @param <R> the type parameter
* @param sync the synchronizer.
* @param argument the argument.
* @param function the function.
* @return the result from the function.
*/
@Nullable
public static <T extends Lockable, @Nullable R> R getInL(T sync, long argument, ObjectLongFunction<T, R> function) {
sync.lock();
try {
return function.apply(sync, argument);
} finally {
sync.unlock();
}
}

private ConcurrentUtils() {
throw new RuntimeException();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.function.Function;
import java.util.function.LongFunction;
import java.util.function.Supplier;
import javasabr.rlib.common.util.pools.Reusable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

Expand Down Expand Up @@ -153,15 +152,4 @@ public static int hash(long value) {
public static int hash(@Nullable Object object) {
return object == null ? 0 : object.hashCode();
}

/**
* Call the method {@link Reusable#release()} if the object is instanceof {@link Reusable}.
*
* @param object the object.
*/
public static void release(@Nullable Object object) {
if (object instanceof Reusable) {
((Reusable) object).release();
}
}
}
17 changes: 17 additions & 0 deletions rlib-common/src/main/java/javasabr/rlib/common/util/Reusable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package javasabr.rlib.common.util;

/**
* @author JavaSaBr
*/
public interface Reusable extends AutoCloseable {

/**
* Cleanup this object
*/
default void cleanup() {}

@Override
default void close() {
cleanup();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import javasabr.rlib.common.util.ArrayUtils;
import javasabr.rlib.common.util.ClassUtils;
import javasabr.rlib.common.util.array.impl.DefaultArrayIterator;
import javasabr.rlib.common.util.pools.Reusable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

Expand All @@ -44,7 +43,7 @@
*/
@NullMarked
@Deprecated
public interface Array<E> extends Collection<E>, Serializable, Reusable, Cloneable, RandomAccess {
public interface Array<E> extends Collection<E>, Serializable, Cloneable, RandomAccess {

/**
* Create an empty read only array.
Expand Down Expand Up @@ -290,11 +289,6 @@ default boolean containsAll(Object[] array) {
return true;
}

@Override
default void free() {
clear();
}

/**
* Removes the element at index possible with reordering.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public void clear() {
}
}

@Override
public void free() {
clear();
}

@Override
public AbstractArray<E> clone() throws CloneNotSupportedException {
return ClassUtils.unsafeNNCast(super.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.io.Serial;
import java.util.Collection;
import java.util.NoSuchElementException;
import javasabr.rlib.common.concurrent.atomic.ReusableAtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;
import javasabr.rlib.common.util.ArrayUtils;
import javasabr.rlib.common.util.array.Array;
import javasabr.rlib.common.util.array.ArrayIterator;
Expand All @@ -30,7 +30,7 @@ public abstract class AbstractConcurrentArray<E> extends AbstractArray<E> implem
/**
* The count of elements in this array.
*/
private final ReusableAtomicInteger size;
private final AtomicInteger size;

/**
* The unsafe array.
Expand All @@ -44,7 +44,7 @@ public AbstractConcurrentArray(Class<? super E> type) {

public AbstractConcurrentArray(Class<? super E> type, int size) {
super(type, size);
this.size = new ReusableAtomicInteger();
this.size = new AtomicInteger();
}

@Override
Expand Down
Loading
Loading