add locking to the terrain database calls

afrisby
Sean Dague 2007-10-23 14:31:35 +00:00
parent 42318dc15a
commit 0d93069adb
1 changed files with 31 additions and 28 deletions

View File

@ -233,12 +233,13 @@ namespace OpenSim.DataStore.MonoSqlite
MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString()); MainLog.Instance.Verbose("DATASTORE", "Storing terrain revision r" + revision.ToString());
DataTable terrain = ds.Tables["terrain"]; DataTable terrain = ds.Tables["terrain"];
lock (ds) {
DataRow newrow = terrain.NewRow(); DataRow newrow = terrain.NewRow();
fillTerrainRow(newrow, regionID, revision, ter); fillTerrainRow(newrow, regionID, revision, ter);
terrain.Rows.Add(newrow); terrain.Rows.Add(newrow);
Commit(); Commit();
}
} }
public double[,] LoadTerrain(LLUUID regionID) public double[,] LoadTerrain(LLUUID regionID)
@ -247,34 +248,36 @@ namespace OpenSim.DataStore.MonoSqlite
terret.Initialize(); terret.Initialize();
DataTable terrain = ds.Tables["terrain"]; DataTable terrain = ds.Tables["terrain"];
lock (ds) {
DataRow[] rows = terrain.Select("RegionUUID = '" + regionID.ToString() + "'","Revision DESC");
int rev = 0;
DataRow[] rows = terrain.Select("RegionUUID = '" + regionID.ToString() + "'","Revision DESC"); if (rows.Length > 0)
int rev = 0;
if (rows.Length > 0)
{
DataRow row = rows[0];
byte[] heightmap = (byte[])row["Heightfield"];
for (int x = 0; x < 256; x++)
{ {
for (int y = 0; y < 256; y++) DataRow row = rows[0];
byte[] heightmap = (byte[])row["Heightfield"];
for (int x = 0; x < 256; x++)
{ {
terret[x, y] = BitConverter.ToDouble(heightmap, ((x * 256) + y) * 8); for (int y = 0; y < 256; y++)
} {
terret[x, y] = BitConverter.ToDouble(heightmap, ((x * 256) + y) * 8);
}
}
rev = (int)row["Revision"];
}
else
{
MainLog.Instance.Verbose("DATASTORE", "No terrain found for region");
return null;
} }
rev = (int)row["Revision"];
MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString());
} }
else
{
MainLog.Instance.Verbose("DATASTORE", "No terrain found for region");
return null;
}
MainLog.Instance.Verbose("DATASTORE", "Loaded terrain revision r" + rev.ToString());
return terret; return terret;
} }