SL_U2_SJ
Obai Albek 2025-05-23 15:12:45 +02:00
parent f015770a77
commit 3e6281177a
1 changed files with 3 additions and 9 deletions

View File

@ -3,7 +3,6 @@ package pp;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import lombok.Synchronized;
import net.jcip.annotations.ThreadSafe;
@ThreadSafe
@ -37,7 +36,6 @@ public class ThreadsafeSimplifiedList<T> implements SimplifiedList<T> {
* @return the element at the specified position in this list
*/
@Override
@Synchronized
public T get(int index) {
this.listLock.lock();
var ptr = this.first;
@ -50,9 +48,8 @@ public class ThreadsafeSimplifiedList<T> implements SimplifiedList<T> {
ptr = ptr.next;
savePtr.lock.unlock();
} else {
return null;
throw new IndexOutOfBoundsException(index + " out of bounds");
}
ptr = ptr.next;
}
try {
return (ptr.element);
@ -72,7 +69,6 @@ public class ThreadsafeSimplifiedList<T> implements SimplifiedList<T> {
*
*/
@Override
@Synchronized
public boolean add(T element) {
this.listLock.lock();
if (this.first != null) {
@ -102,12 +98,11 @@ public class ThreadsafeSimplifiedList<T> implements SimplifiedList<T> {
* @return the element previously at the specified position
*/
@Override
@Synchronized
public T set(int index, T element) {
this.listLock.lock();
var ptr = this.first;
ptr.lock.lock();
this.listLock.lock();
this.listLock.unlock();
for (var j = 0; j < index; j++) {
if (ptr.next != null) {
ptr.next.lock.lock();
@ -115,7 +110,7 @@ public class ThreadsafeSimplifiedList<T> implements SimplifiedList<T> {
ptr = ptr.next;
saveNode.lock.unlock();
} else {
return null;
throw new IndexOutOfBoundsException(index + " out of bounds");
}
}
var prevElement = ptr.element;
@ -130,7 +125,6 @@ public class ThreadsafeSimplifiedList<T> implements SimplifiedList<T> {
* @return true if this list contains no elements
*/
@Override
@Synchronized
public boolean isEmpty() {
this.listLock.lock();
try {