Simplify UuidGatherer by performing asset fetch synchronously rather than using the async call but waiting for completion anyway!

0.7.4-extended
Justin Clark-Casey (justincc) 2012-09-21 01:36:23 +01:00
parent d31a951d94
commit 8068c083f6
1 changed files with 44 additions and 40 deletions

View File

@ -57,17 +57,17 @@ namespace OpenSim.Region.Framework.Scenes
/// Asset cache used for gathering assets
/// </summary>
protected IAssetService m_assetCache;
/// <summary>
/// Used as a temporary store of an asset which represents an object. This can be a null if no appropriate
/// asset was found by the asset service.
/// </summary>
private AssetBase m_requestedObjectAsset;
/// <summary>
/// Signal whether we are currently waiting for the asset service to deliver an asset.
/// </summary>
private bool m_waitingForObjectAsset;
// /// <summary>
// /// Used as a temporary store of an asset which represents an object. This can be a null if no appropriate
// /// asset was found by the asset service.
// /// </summary>
// private AssetBase m_requestedObjectAsset;
//
// /// <summary>
// /// Signal whether we are currently waiting for the asset service to deliver an asset.
// /// </summary>
// private bool m_waitingForObjectAsset;
public UuidGatherer(IAssetService assetCache)
{
@ -195,18 +195,18 @@ namespace OpenSim.Region.Framework.Scenes
}
}
/// <summary>
/// The callback made when we request the asset for an object from the asset service.
/// </summary>
private void AssetReceived(string id, Object sender, AssetBase asset)
{
lock (this)
{
m_requestedObjectAsset = asset;
m_waitingForObjectAsset = false;
Monitor.Pulse(this);
}
}
// /// <summary>
// /// The callback made when we request the asset for an object from the asset service.
// /// </summary>
// private void AssetReceived(string id, Object sender, AssetBase asset)
// {
// lock (this)
// {
// m_requestedObjectAsset = asset;
// m_waitingForObjectAsset = false;
// Monitor.Pulse(this);
// }
// }
/// <summary>
/// Get an asset synchronously, potentially using an asynchronous callback. If the
@ -216,25 +216,29 @@ namespace OpenSim.Region.Framework.Scenes
/// <returns></returns>
protected virtual AssetBase GetAsset(UUID uuid)
{
m_waitingForObjectAsset = true;
m_assetCache.Get(uuid.ToString(), this, AssetReceived);
return m_assetCache.Get(uuid.ToString());
// The asset cache callback can either
//
// 1. Complete on the same thread (if the asset is already in the cache) or
// 2. Come in via a different thread (if we need to go fetch it).
//
// The code below handles both these alternatives.
lock (this)
{
if (m_waitingForObjectAsset)
{
Monitor.Wait(this);
m_waitingForObjectAsset = false;
}
}
return m_requestedObjectAsset;
// XXX: Switching to do this synchronously where the call was async before but we always waited for it
// to complete anyway!
// m_waitingForObjectAsset = true;
// m_assetCache.Get(uuid.ToString(), this, AssetReceived);
//
// // The asset cache callback can either
// //
// // 1. Complete on the same thread (if the asset is already in the cache) or
// // 2. Come in via a different thread (if we need to go fetch it).
// //
// // The code below handles both these alternatives.
// lock (this)
// {
// if (m_waitingForObjectAsset)
// {
// Monitor.Wait(this);
// m_waitingForObjectAsset = false;
// }
// }
//
// return m_requestedObjectAsset;
}
/// <summary>