|
|
|
@ -10,9 +10,9 @@ namespace FLocal.Core { |
|
|
|
|
|
|
|
|
|
internal static readonly Registry<TKey, TData> instance = new Registry<TKey,TData>(); |
|
|
|
|
|
|
|
|
|
private Dictionary<TKey, TData> storage; |
|
|
|
|
private volatile Dictionary<TKey, TData> storage; |
|
|
|
|
|
|
|
|
|
private Dictionary<TKey, object> locks; |
|
|
|
|
private volatile Dictionary<TKey, object> locks; |
|
|
|
|
|
|
|
|
|
private Registry() { |
|
|
|
|
this.storage = new Dictionary<TKey,TData>(); |
|
|
|
@ -20,23 +20,15 @@ namespace FLocal.Core { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal TData Get(TKey id, bool forLoadingFromHash) { |
|
|
|
|
if(!this.locks.ContainsKey(id)) { |
|
|
|
|
if(!this.storage.ContainsKey(id)) { |
|
|
|
|
lock(this.locks) { |
|
|
|
|
if(!this.locks.ContainsKey(id)) { |
|
|
|
|
this.locks.Add(id, new object()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
lock(this.locks[id]) { |
|
|
|
|
if(!this.storage.ContainsKey(id)) { |
|
|
|
|
|
|
|
|
|
//this.storage[id] = IDataObject<TKey, TData>.CreateByIdFromRegistry(id); |
|
|
|
|
//this.storage[id] = TData.CreateByIdFromRegistry(id); |
|
|
|
|
TData obj = new TData(); |
|
|
|
|
obj.CreateByIdFromRegistry(id, forLoadingFromHash); |
|
|
|
|
this.storage[id] = obj; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lock(this.locks) { |
|
|
|
|
if(this.storage.ContainsKey(id)) { |
|
|
|
@ -58,16 +50,12 @@ namespace FLocal.Core { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal void Delete(TKey[] idsToDelete) { |
|
|
|
|
lock(this.locks) { |
|
|
|
|
foreach(TKey id in idsToDelete) { |
|
|
|
|
lock(this.locks[id]) { |
|
|
|
|
IDataObject<TKey, TData> obj = null; |
|
|
|
|
lock(this.locks) { |
|
|
|
|
if(this.storage.ContainsKey(id)) { |
|
|
|
|
obj = this.storage[id]; |
|
|
|
|
this.storage.Remove(id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(obj != null) { |
|
|
|
|
obj.markAsDeletedFromRegistry(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|