mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-03 13:36:44 +01:00
properly implement locks
This commit is contained in:
parent
c0b3e80d1d
commit
c06f3e0d76
1 changed files with 33 additions and 49 deletions
|
@ -29,8 +29,6 @@ public class LongHashset extends LongHash
|
||||||
public void add(long key) {
|
public void add(long key) {
|
||||||
int mainIdx = (int) (key & 255);
|
int mainIdx = (int) (key & 255);
|
||||||
int outerIdx = (int) ((key >> 32) & 255);
|
int outerIdx = (int) ((key >> 32) & 255);
|
||||||
rl.lock();
|
|
||||||
try {
|
|
||||||
wl.lock();
|
wl.lock();
|
||||||
try {
|
try {
|
||||||
long outer[][] = values[mainIdx], inner[];
|
long outer[][] = values[mainIdx], inner[];
|
||||||
|
@ -58,9 +56,6 @@ public class LongHashset extends LongHash
|
||||||
} finally {
|
} finally {
|
||||||
wl.unlock();
|
wl.unlock();
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
rl.unlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsKey(long key) {
|
public boolean containsKey(long key) {
|
||||||
|
@ -87,7 +82,7 @@ public class LongHashset extends LongHash
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(long key) {
|
public void remove(long key) {
|
||||||
rl.lock();
|
wl.lock();
|
||||||
try {
|
try {
|
||||||
long[][] outer = this.values[(int) (key & 255)];
|
long[][] outer = this.values[(int) (key & 255)];
|
||||||
if (outer == null)
|
if (outer == null)
|
||||||
|
@ -100,26 +95,21 @@ public class LongHashset extends LongHash
|
||||||
int max = inner.length - 1;
|
int max = inner.length - 1;
|
||||||
for (int i = 0; i <= max; i++) {
|
for (int i = 0; i <= max; i++) {
|
||||||
if (inner[i] == key) {
|
if (inner[i] == key) {
|
||||||
wl.lock();
|
|
||||||
try {
|
|
||||||
count--;
|
count--;
|
||||||
if (i != max) {
|
if (i != max) {
|
||||||
inner[i] = inner[max];
|
inner[i] = inner[max];
|
||||||
}
|
}
|
||||||
outer[(int) ((key >> 32) & 255)] = (max == 0 ? null : Arrays_copyOf(inner, max));
|
outer[(int) ((key >> 32) & 255)] = (max == 0 ? null : Arrays_copyOf(inner, max));
|
||||||
} finally {
|
|
||||||
wl.unlock();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
rl.unlock();
|
wl.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long popFirst() {
|
public long popFirst() {
|
||||||
rl.lock();
|
wl.lock();
|
||||||
try {
|
try {
|
||||||
for (long[][] outer : values) {
|
for (long[][] outer : values) {
|
||||||
if (outer == null)
|
if (outer == null)
|
||||||
|
@ -128,21 +118,15 @@ public class LongHashset extends LongHash
|
||||||
long[] inner = outer[i];
|
long[] inner = outer[i];
|
||||||
if (inner == null || inner.length == 0)
|
if (inner == null || inner.length == 0)
|
||||||
continue;
|
continue;
|
||||||
wl.lock();
|
|
||||||
try {
|
|
||||||
count--;
|
count--;
|
||||||
long ret = inner[inner.length - 1];
|
long ret = inner[inner.length - 1];
|
||||||
outer[i] = Arrays_copyOf(inner, inner.length - 1);
|
outer[i] = Arrays_copyOf(inner, inner.length - 1);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
wl.unlock();
|
wl.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
rl.unlock();
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue