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

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