forked from mirrors/NBTExplorer
Made sure that all access to sectorFree is moved to inside the protected area as well.
This commit is contained in:
parent
6326bdac82
commit
258eff946b
1 changed files with 42 additions and 40 deletions
|
@ -26,6 +26,7 @@ namespace Substrate.Core
|
|||
/// The file lock used so that we do not seek in different areas
|
||||
/// of the same file at the same time. All file access should lock this
|
||||
/// object before moving the file pointer.
|
||||
/// The lock should also surround all access to the sectorFree free variable.
|
||||
/// </summary>
|
||||
private object fileLock = new object();
|
||||
|
||||
|
@ -245,12 +246,13 @@ namespace Substrate.Core
|
|||
int sectorNumber = offset >> 8;
|
||||
int numSectors = offset & 0xFF;
|
||||
|
||||
lock (this.fileLock)
|
||||
{
|
||||
if (sectorNumber + numSectors > sectorFree.Count) {
|
||||
Debugln("READ", x, z, "invalid sector");
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (this.fileLock) {
|
||||
file.Seek(sectorNumber * SectorBytes, SeekOrigin.Begin);
|
||||
byte[] lengthBytes = new byte[4];
|
||||
file.Read(lengthBytes, 0, 4);
|
||||
|
@ -381,6 +383,7 @@ namespace Substrate.Core
|
|||
else {
|
||||
/* we need to allocate new sectors */
|
||||
|
||||
lock (this.fileLock) {
|
||||
/* mark the sectors previously used for this chunk as free */
|
||||
for (int i = 0; i < sectorsAllocated; ++i) {
|
||||
sectorFree[sectorNumber + i] = true;
|
||||
|
@ -420,7 +423,6 @@ namespace Substrate.Core
|
|||
* no free space large enough found -- we need to grow the
|
||||
* file
|
||||
*/
|
||||
lock (this.fileLock) {
|
||||
Debug("SAVE", x, z, length, "grow");
|
||||
file.Seek(0, SeekOrigin.End);
|
||||
sectorNumber = sectorFree.Count;
|
||||
|
|
Loading…
Reference in a new issue