From f161a2dfc9fb66474a4d4ae9c0574e7d19d13360 Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Wed, 20 Nov 2013 22:12:44 +0000
Subject: [PATCH] BOB: NamedDB accesses are synchronized, correct findbugs fix
 is to remove volatile

---
 apps/BOB/src/net/i2p/BOB/NamedDB.java | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/apps/BOB/src/net/i2p/BOB/NamedDB.java b/apps/BOB/src/net/i2p/BOB/NamedDB.java
index b3c0741f57..5a1b8e45f3 100644
--- a/apps/BOB/src/net/i2p/BOB/NamedDB.java
+++ b/apps/BOB/src/net/i2p/BOB/NamedDB.java
@@ -15,8 +15,6 @@
  */
 package net.i2p.BOB;
 
-import java.util.concurrent.atomic.AtomicInteger;
-
 /**
  * Internal database to relate nicknames to options to values
  *
@@ -25,9 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 public class NamedDB {
 
 	private volatile Object[][] data;
-	private volatile int index;
-	private final AtomicInteger writersWaiting = new AtomicInteger();
-	private final AtomicInteger readers = new AtomicInteger();
+	private int index,  writersWaiting,  readers;
 
 	/**
 	 * make initial NULL object
@@ -35,27 +31,26 @@ public class NamedDB {
 	 */
 	public NamedDB() {
 		this.data = new Object[1][2];
-		this.index = 0;
 	}
 
 	synchronized public void getReadLock() {
-		while ((writersWaiting.get() != 0)) {
+		while ((writersWaiting != 0)) {
 			try {
 				wait();
 			} catch (InterruptedException ie) {
 			}
 		}
-		readers.incrementAndGet();
+		readers++;
 	}
 
 	synchronized public void releaseReadLock() {
-		readers.decrementAndGet();
+		readers--;
 		notifyAll();
 	}
 
 	synchronized public void getWriteLock() {
-		writersWaiting.incrementAndGet();
-		while (readers.get() != 0 && writersWaiting.get() != 1) {
+		writersWaiting++;
+		while (readers != 0 && writersWaiting != 1) {
 			try {
 				wait();
 			} catch (InterruptedException ie) {
@@ -64,7 +59,7 @@ public class NamedDB {
 	}
 
 	synchronized public void releaseWriteLock() {
-		writersWaiting.decrementAndGet();
+		writersWaiting--;
 		notifyAll();
 	}
 
-- 
GitLab