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

connector_plugin
Justin Clark-Casey (justincc) 2012-09-21 01:36:23 +01:00
parent 1b0abf8f0c
commit bceef401fa
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!
// m_waitingForObjectAsset = true;
// m_assetCache.Get(uuid.ToString(), this, AssetReceived);
// //
// 1. Complete on the same thread (if the asset is already in the cache) or // // The asset cache callback can either
// 2. Come in via a different thread (if we need to go fetch it). // //
// // 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;
// }
// }
// //
// The code below handles both these alternatives. // return m_requestedObjectAsset;
lock (this)
{
if (m_waitingForObjectAsset)
{
Monitor.Wait(this);
m_waitingForObjectAsset = false;
}
}
return m_requestedObjectAsset;
} }
/// <summary> /// <summary>