HTTPCacheFileLock.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if !BESTHTTP_DISABLE_CACHING && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.Collections.Generic;
  4. namespace BestHTTP.Caching
  5. {
  6. sealed class HTTPCacheFileLock
  7. {
  8. private static Dictionary<Uri, object> FileLocks = new Dictionary<Uri, object>();
  9. private static object SyncRoot = new object();
  10. internal static object Acquire(Uri uri)
  11. {
  12. lock (SyncRoot)
  13. {
  14. object fileLock;
  15. if (!FileLocks.TryGetValue(uri, out fileLock))
  16. FileLocks.Add(uri, fileLock = new object());
  17. return fileLock;
  18. }
  19. }
  20. internal static void Remove(Uri uri)
  21. {
  22. lock (SyncRoot)
  23. {
  24. if (FileLocks.ContainsKey(uri))
  25. FileLocks.Remove(uri);
  26. }
  27. }
  28. internal static void Clear()
  29. {
  30. lock (SyncRoot)
  31. {
  32. FileLocks.Clear();
  33. }
  34. }
  35. }
  36. }
  37. #endif