From 6804f9affba63e8f39f207769f026e9fcda70d94 Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Thu, 25 Oct 2007 15:17:42 +0000
Subject: * Added static mutex to terrain load-tile to prevent file IO locking
issues.
---
.../Region/Terrain.BasicTerrain/TerrainEngine.cs | 51 +++++++++++++---------
1 file changed, 31 insertions(+), 20 deletions(-)
(limited to 'OpenSim/Region/Terrain.BasicTerrain')
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
index d010a03..c8c6e51 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
@@ -51,6 +51,8 @@ namespace OpenSim.Region.Terrain
public class TerrainEngine
{
+ public static System.Threading.Mutex fileIOLock = new System.Threading.Mutex();
+
///
/// Plugin library for scripts
///
@@ -731,36 +733,45 @@ namespace OpenSim.Region.Terrain
/// Where do the region coords start for this terrain?
public void LoadFromFileF32(string filename, int dimensionX, int dimensionY, int lowerboundX, int lowerboundY)
{
- int sectionToLoadX = ((this.offsetX - lowerboundX) * this.w);
- int sectionToLoadY = ((this.offsetY - lowerboundY) * this.h);
+ fileIOLock.WaitOne();
+ try
+ {
- double[,] tempMap = new double[dimensionX, dimensionY];
+ int sectionToLoadX = ((this.offsetX - lowerboundX) * this.w);
+ int sectionToLoadY = ((this.offsetY - lowerboundY) * this.h);
- FileInfo file = new FileInfo(filename);
- FileStream s = file.Open(FileMode.Open, FileAccess.Read);
- BinaryReader bs = new BinaryReader(s);
+ double[,] tempMap = new double[dimensionX, dimensionY];
- int x, y;
- for (x = 0; x < dimensionX; x++)
- {
- for (y = 0; y < dimensionY; y++)
+ FileInfo file = new FileInfo(filename);
+ FileStream s = file.Open(FileMode.Open, FileAccess.Read);
+ BinaryReader bs = new BinaryReader(s);
+
+ int x, y;
+ for (x = 0; x < dimensionX; x++)
{
- tempMap[x,y] = (double)bs.ReadSingle();
+ for (y = 0; y < dimensionY; y++)
+ {
+ tempMap[x, y] = (double)bs.ReadSingle();
+ }
}
- }
- for (y = 0; y < h; y++)
- {
- for (x = 0; x < w; x++)
+ for (y = 0; y < h; y++)
{
- heightmap.Set(x, y, tempMap[x + sectionToLoadX, y + sectionToLoadY]);
+ for (x = 0; x < w; x++)
+ {
+ heightmap.Set(x, y, tempMap[x + sectionToLoadX, y + sectionToLoadY]);
+ }
}
- }
- bs.Close();
- s.Close();
+ bs.Close();
+ s.Close();
- tainted++;
+ tainted++;
+ }
+ finally
+ {
+ fileIOLock.ReleaseMutex();
+ }
}
///
--
cgit v1.1