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
Expand Up @@ -1001,19 +1001,29 @@ public boolean hasNonEmptySection(int layer) {

@Override
@SuppressWarnings("unchecked")
public synchronized boolean trim(boolean aggressive) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
public boolean trim(boolean aggressive) {
synchronized (this) {
if (sections == null && (!aggressive || levelChunk == null)) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
return !aggressive || super.trim(true);
}
}
if (aggressive) {
sectionLock.writeLock().lock();
sections = null;
levelChunk = null;
sectionLock.writeLock().unlock();
return super.trim(true);
} else if (sections == null) {
// don't bother trimming if there are no sections stored.
return true;
} else {
try {
synchronized (this) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
sections = null;
levelChunk = null;
return super.trim(true);
}
} finally {
sectionLock.writeLock().unlock();
}
}
synchronized (this) {
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
int layer = i - getMinSectionPosition();
if (!hasSection(i) || super.blocks[layer] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,19 +1002,29 @@ public boolean hasNonEmptySection(int layer) {

@Override
@SuppressWarnings("unchecked")
public synchronized boolean trim(boolean aggressive) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
public boolean trim(boolean aggressive) {
synchronized (this) {
if (sections == null && (!aggressive || levelChunk == null)) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
return !aggressive || super.trim(true);
}
}
if (aggressive) {
sectionLock.writeLock().lock();
sections = null;
levelChunk = null;
sectionLock.writeLock().unlock();
return super.trim(true);
} else if (sections == null) {
// don't bother trimming if there are no sections stored.
return true;
} else {
try {
synchronized (this) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
sections = null;
levelChunk = null;
return super.trim(true);
}
} finally {
sectionLock.writeLock().unlock();
}
}
synchronized (this) {
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
int layer = i - getMinSectionPosition();
if (!hasSection(i) || super.blocks[layer] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,19 +1003,29 @@ public boolean hasNonEmptySection(int layer) {

@Override
@SuppressWarnings("unchecked")
public synchronized boolean trim(boolean aggressive) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
public boolean trim(boolean aggressive) {
synchronized (this) {
if (sections == null && (!aggressive || levelChunk == null)) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
return !aggressive || super.trim(true);
}
}
if (aggressive) {
sectionLock.writeLock().lock();
sections = null;
levelChunk = null;
sectionLock.writeLock().unlock();
return super.trim(true);
} else if (sections == null) {
// don't bother trimming if there are no sections stored.
return true;
} else {
try {
synchronized (this) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
sections = null;
levelChunk = null;
return super.trim(true);
}
} finally {
sectionLock.writeLock().unlock();
}
}
synchronized (this) {
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
int layer = i - getMinSectionPosition();
if (!hasSection(i) || super.blocks[layer] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,19 +1037,29 @@ public boolean hasNonEmptySection(int layer) {

@Override
@SuppressWarnings("unchecked")
public synchronized boolean trim(boolean aggressive) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
public boolean trim(boolean aggressive) {
synchronized (this) {
if (sections == null && (!aggressive || levelChunk == null)) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
return !aggressive || super.trim(true);
}
}
if (aggressive) {
sectionLock.writeLock().lock();
sections = null;
levelChunk = null;
sectionLock.writeLock().unlock();
return super.trim(true);
} else if (sections == null) {
// don't bother trimming if there are no sections stored.
return true;
} else {
try {
synchronized (this) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
sections = null;
levelChunk = null;
return super.trim(true);
}
} finally {
sectionLock.writeLock().unlock();
}
}
synchronized (this) {
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
int layer = i - getMinSectionPosition();
if (!hasSection(i) || super.blocks[layer] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,19 +996,29 @@ public boolean hasNonEmptySection(int layer) {

@Override
@SuppressWarnings("unchecked")
public synchronized boolean trim(boolean aggressive) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
public boolean trim(boolean aggressive) {
synchronized (this) {
if (sections == null && (!aggressive || levelChunk == null)) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
return !aggressive || super.trim(true);
}
}
if (aggressive) {
sectionLock.writeLock().lock();
sections = null;
levelChunk = null;
sectionLock.writeLock().unlock();
return super.trim(true);
} else if (sections == null) {
// don't bother trimming if there are no sections stored.
return true;
} else {
try {
synchronized (this) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
sections = null;
levelChunk = null;
return super.trim(true);
}
} finally {
sectionLock.writeLock().unlock();
}
}
synchronized (this) {
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
int layer = i - getMinSectionPosition();
if (!hasSection(i) || super.blocks[layer] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,19 +996,29 @@ public boolean hasNonEmptySection(int layer) {

@Override
@SuppressWarnings("unchecked")
public synchronized boolean trim(boolean aggressive) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
public boolean trim(boolean aggressive) {
synchronized (this) {
if (sections == null && (!aggressive || levelChunk == null)) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
return !aggressive || super.trim(true);
}
}
if (aggressive) {
sectionLock.writeLock().lock();
sections = null;
levelChunk = null;
sectionLock.writeLock().unlock();
return super.trim(true);
} else if (sections == null) {
// don't bother trimming if there are no sections stored.
return true;
} else {
try {
synchronized (this) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
sections = null;
levelChunk = null;
return super.trim(true);
}
} finally {
sectionLock.writeLock().unlock();
}
}
synchronized (this) {
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
int layer = i - getMinSectionPosition();
if (!hasSection(i) || super.blocks[layer] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,19 +1004,29 @@ public boolean hasNonEmptySection(int layer) {

@Override
@SuppressWarnings("unchecked")
public synchronized boolean trim(boolean aggressive) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
public boolean trim(boolean aggressive) {
synchronized (this) {
if (sections == null && (!aggressive || levelChunk == null)) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
return !aggressive || super.trim(true);
}
}
if (aggressive) {
sectionLock.writeLock().lock();
sections = null;
levelChunk = null;
sectionLock.writeLock().unlock();
return super.trim(true);
} else if (sections == null) {
// don't bother trimming if there are no sections stored.
return true;
} else {
try {
synchronized (this) {
skyLight = new DataLayer[getSectionCount()];
blockLight = new DataLayer[getSectionCount()];
sections = null;
levelChunk = null;
return super.trim(true);
}
Comment thread
dordsor21 marked this conversation as resolved.
} finally {
sectionLock.writeLock().unlock();
}
}
synchronized (this) {
for (int i = getMinSectionPosition(); i <= getMaxSectionPosition(); i++) {
int layer = i - getMinSectionPosition();
if (!hasSection(i) || super.blocks[layer] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public synchronized boolean trim(boolean aggressive) {
if (!aggressive) {
return false;
}
synchronized (igb) {
igb.trim(true);
}
// Don't synchronise here, let the implementation handle it
igb.trim(true);
}
}
return result;
Expand Down
Loading