Skip to content
Snippets Groups Projects
Verified Commit b2faf630 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Revert DatabaseAccessManager to buggy implementation

parent 7f4e421b
1 merge request!4f-fix-deadlock -> dev
Pipeline #5392 failed
......@@ -26,7 +26,6 @@
package org.caosdb.server.database;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import org.caosdb.server.database.access.Access;
import org.caosdb.server.database.access.AccessControlAccess;
......@@ -57,7 +56,7 @@ import org.caosdb.server.utils.Releasable;
class ReadAccessSemaphore extends Semaphore implements Releasable {
private static final long serialVersionUID = 4384921156838881337L;
private AtomicInteger acquired = new AtomicInteger(0); // how many threads have read access
private int acquired = 0; // how many threads have read access
Semaphore writersBlock =
new Semaphore(1, true); // This semaphore is blocked as long as there are any
// unreleased read permits.
......@@ -74,9 +73,10 @@ class ReadAccessSemaphore extends Semaphore implements Releasable {
@Override
public void acquire() throws InterruptedException {
super.acquire(); // Protect the next few lines
if (this.acquired.getAndIncrement() == 0) {
if (this.acquired == 0) {
this.writersBlock.acquire();
}
this.acquired++;
super.release();
}
......@@ -87,7 +87,9 @@ class ReadAccessSemaphore extends Semaphore implements Releasable {
*/
@Override
public void release() {
if (this.acquired.decrementAndGet() == 0) { // Last permit: release
this.acquired--;
if (this.acquired <= 0) { // Last permit: release
this.acquired = 0;
if (this.writersBlock.availablePermits() <= 0) {
this.writersBlock.release();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment