aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs104
1 files changed, 22 insertions, 82 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index c6f41a6..0112198 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -46,7 +46,7 @@ namespace OpenSim.Framework.Communications.Cache
46 /// sends packetised data directly back to the client. The only point where they meet is AssetReceived() and 46 /// sends packetised data directly back to the client. The only point where they meet is AssetReceived() and
47 /// AssetNotFound(), which means they do share the same asset and texture caches. 47 /// AssetNotFound(), which means they do share the same asset and texture caches.
48 /// 48 ///
49 /// TODO Assets in this cache are effectively immortal (they are never disposed off through old age). 49 /// TODO: Assets in this cache are effectively immortal (they are never disposed of through old age).
50 /// This is not a huge problem at the moment since other memory use usually dwarfs that used by assets 50 /// This is not a huge problem at the moment since other memory use usually dwarfs that used by assets
51 /// but it's something to bear in mind. 51 /// but it's something to bear in mind.
52 /// </summary> 52 /// </summary>
@@ -206,24 +206,9 @@ namespace OpenSim.Framework.Communications.Cache
206 /// <summary> 206 /// <summary>
207 /// Only get an asset if we already have it in the cache. 207 /// Only get an asset if we already have it in the cache.
208 /// </summary> 208 /// </summary>
209 /// <param name="assetId"></param></param> 209 /// <param name="assetId"></param>
210 /// <returns></returns> 210 /// <param name="asset"></param>
211 //private AssetBase GetCachedAsset(UUID assetId) 211 /// <returns>true if the asset was in the cache, false if it was not</returns>
212 //{
213 // AssetBase asset = null;
214
215 // if (Textures.ContainsKey(assetId))
216 // {
217 // asset = Textures[assetId];
218 // }
219 // else if (Assets.ContainsKey(assetId))
220 // {
221 // asset = Assets[assetId];
222 // }
223
224 // return asset;
225 //}
226
227 private bool TryGetCachedAsset(UUID assetId, out AssetBase asset) 212 private bool TryGetCachedAsset(UUID assetId, out AssetBase asset)
228 { 213 {
229 if (Textures.ContainsKey(assetId)) 214 if (Textures.ContainsKey(assetId))
@@ -451,42 +436,21 @@ namespace OpenSim.Framework.Communications.Cache
451 } 436 }
452 437
453 // Notify requesters for this asset 438 // Notify requesters for this asset
454 if (RequestLists.ContainsKey(asset.FullID)) 439 AssetRequestsList reqList = null;
455 { 440
456 AssetRequestsList reqList = null; 441 lock (RequestLists)
457 lock (RequestLists) 442 {
458 { 443 if (RequestLists.TryGetValue(asset.FullID, out reqList))
459 //m_log.Info("AssetCache: Lock taken on requestLists (AssetReceived #1)"); 444 RequestLists.Remove(asset.FullID);
460 reqList = RequestLists[asset.FullID]; 445 }
461 446
462 } 447 if (reqList != null)
463 //m_log.Info("AssetCache: Lock released on requestLists (AssetReceived #1)"); 448 {
464 if (reqList != null) 449 foreach (NewAssetRequest req in reqList.Requests)
465 { 450 {
466 //making a copy of the list is not ideal 451 // Xantor 20080526 are we really calling all the callbacks if multiple queued for 1 request? -- Yes, checked
467 //but the old method of locking around this whole block of code was causing a multi-thread lock 452 // m_log.DebugFormat("[ASSET CACHE]: Callback for asset {0}", asset.FullID);
468 //between this and the TextureDownloadModule 453 req.Callback(asset.FullID, asset);
469 //while the localAsset thread running this and trying to send a texture to the callback in the
470 //texturedownloadmodule , and hitting a lock in there. While the texturedownload thread (which was holding
471 // the lock in the texturedownload module) was trying to
472 //request a new asset and hitting a lock in here on the RequestLists.
473
474 List<NewAssetRequest> theseRequests = new List<NewAssetRequest>(reqList.Requests);
475 reqList.Requests.Clear();
476
477 lock (RequestLists)
478 {
479 // m_log.Info("AssetCache: Lock taken on requestLists (AssetReceived #2)");
480 RequestLists.Remove(asset.FullID);
481 }
482 //m_log.Info("AssetCache: Lock released on requestLists (AssetReceived #2)");
483
484 foreach (NewAssetRequest req in theseRequests)
485 {
486 // Xantor 20080526 are we really calling all the callbacks if multiple queued for 1 request? -- Yes, checked
487 // m_log.DebugFormat("[ASSET CACHE]: Callback for asset {0}", asset.FullID);
488 req.Callback(asset.FullID, asset);
489 }
490 } 454 }
491 } 455 }
492 } 456 }
@@ -509,27 +473,13 @@ namespace OpenSim.Framework.Communications.Cache
509 AssetRequestsList reqList = null; 473 AssetRequestsList reqList = null;
510 lock (RequestLists) 474 lock (RequestLists)
511 { 475 {
512 // m_log.Info("AssetCache: Lock taken on requestLists (AssetNotFound #1)"); 476 if (RequestLists.TryGetValue(assetID, out reqList))
513 if (RequestLists.ContainsKey(assetID)) 477 RequestLists.Remove(assetID);
514 {
515 reqList = RequestLists[assetID];
516 }
517 } 478 }
518 // m_log.Info("AssetCache: Lock released on requestLists (AssetNotFound #1)");
519 479
520 if (reqList != null) 480 if (reqList != null)
521 { 481 {
522 List<NewAssetRequest> theseRequests = new List<NewAssetRequest>(reqList.Requests); 482 foreach (NewAssetRequest req in reqList.Requests)
523 reqList.Requests.Clear();
524
525 lock (RequestLists)
526 {
527 // m_log.Info("AssetCache: Lock taken on requestLists (AssetNotFound #2)");
528 RequestLists.Remove(assetID);
529 }
530 // m_log.Info("AssetCache: Lock released on requestLists (AssetNotFound #2)");
531
532 foreach (NewAssetRequest req in theseRequests)
533 { 483 {
534 req.Callback(assetID, null); 484 req.Callback(assetID, null);
535 } 485 }
@@ -578,6 +528,7 @@ namespace OpenSim.Framework.Communications.Cache
578 source = 3; 528 source = 3;
579 //Console.WriteLine("asset request " + requestID); 529 //Console.WriteLine("asset request " + requestID);
580 } 530 }
531
581 //check to see if asset is in local cache, if not we need to request it from asset server. 532 //check to see if asset is in local cache, if not we need to request it from asset server.
582 //Console.WriteLine("asset request " + requestID); 533 //Console.WriteLine("asset request " + requestID);
583 if (!Assets.ContainsKey(requestID)) 534 if (!Assets.ContainsKey(requestID))
@@ -636,6 +587,7 @@ namespace OpenSim.Framework.Communications.Cache
636 //no requests waiting 587 //no requests waiting
637 return; 588 return;
638 } 589 }
590
639 // if less than 5, do all of them 591 // if less than 5, do all of them
640 int num = Math.Min(5, AssetRequests.Count); 592 int num = Math.Min(5, AssetRequests.Count);
641 593
@@ -688,18 +640,10 @@ namespace OpenSim.Framework.Communications.Cache
688 //public bool AssetInCache; 640 //public bool AssetInCache;
689 //public int TimeRequested; 641 //public int TimeRequested;
690 public int DiscardLevel = -1; 642 public int DiscardLevel = -1;
691
692 public AssetRequest()
693 {
694 }
695 } 643 }
696 644
697 public class AssetInfo : AssetBase 645 public class AssetInfo : AssetBase
698 { 646 {
699 public AssetInfo()
700 {
701 }
702
703 public AssetInfo(AssetBase aBase) 647 public AssetInfo(AssetBase aBase)
704 { 648 {
705 Data = aBase.Data; 649 Data = aBase.Data;
@@ -712,10 +656,6 @@ namespace OpenSim.Framework.Communications.Cache
712 656
713 public class TextureImage : AssetBase 657 public class TextureImage : AssetBase
714 { 658 {
715 public TextureImage()
716 {
717 }
718
719 public TextureImage(AssetBase aBase) 659 public TextureImage(AssetBase aBase)
720 { 660 {
721 Data = aBase.Data; 661 Data = aBase.Data;