forked from wuxiongbin/XIL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c3716a
commit d6c7961
Showing
7 changed files
with
1,467 additions
and
1,163 deletions.
There are no files selected for viewing
262 changes: 130 additions & 132 deletions
262
Assets/XIL/ILSource/ILRuntime/Other/ThreadSafeDictionary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,130 @@ | ||
#if USE_HOTusing System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using System.Runtime.Versioning; | ||
using System.Threading; | ||
|
||
namespace ILRuntime.Other | ||
{ | ||
/// <summary> | ||
/// A thread safe dictionary for internal use | ||
/// </summary> | ||
/// <typeparam name="K"></typeparam> | ||
/// <typeparam name="V"></typeparam> | ||
class ThreadSafeDictionary<K, V> : IDictionary<K, V> | ||
{ | ||
Dictionary<K, V> dic = new Dictionary<K, V>(); | ||
|
||
public Dictionary<K,V> InnerDictionary { get { return dic; } } | ||
public V this[K key] | ||
{ | ||
get | ||
{ | ||
lock(dic) | ||
return dic[key]; | ||
} | ||
|
||
set | ||
{ | ||
lock(dic) | ||
dic[key] = value; | ||
} | ||
} | ||
|
||
public int Count | ||
{ | ||
get | ||
{ | ||
lock(dic) | ||
return dic.Count; | ||
} | ||
} | ||
|
||
public bool IsReadOnly | ||
{ | ||
get | ||
{ | ||
lock(dic) | ||
return IsReadOnly; | ||
} | ||
} | ||
|
||
public ICollection<K> Keys | ||
{ | ||
get | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public ICollection<V> Values | ||
{ | ||
get | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public void Add(KeyValuePair<K, V> item) | ||
{ | ||
lock (dic) | ||
dic.Add(item.Key, item.Value); | ||
} | ||
|
||
public void Add(K key, V value) | ||
{ | ||
lock(dic) | ||
dic.Add(key, value); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
lock(dic) | ||
dic.Clear(); | ||
} | ||
|
||
public bool Contains(KeyValuePair<K, V> item) | ||
{ | ||
lock(dic) | ||
return dic.ContainsKey(item.Key); | ||
} | ||
|
||
public bool ContainsKey(K key) | ||
{ | ||
lock(dic) | ||
return dic.ContainsKey(key); | ||
} | ||
|
||
public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IEnumerator<KeyValuePair<K, V>> GetEnumerator() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public bool Remove(KeyValuePair<K, V> item) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public bool Remove(K key) | ||
{ | ||
lock(dic) | ||
return dic.Remove(key); | ||
} | ||
|
||
public bool TryGetValue(K key, out V value) | ||
{ | ||
lock(dic) | ||
return dic.TryGetValue(key, out value); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
}#endif | ||
#if USE_HOT | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics; | ||
using System.Runtime.Versioning; | ||
using System.Threading; | ||
|
||
namespace ILRuntime.Other | ||
{ | ||
/// <summary> | ||
/// A thread safe dictionary for internal use | ||
/// </summary> | ||
/// <typeparam name="K"></typeparam> | ||
/// <typeparam name="V"></typeparam> | ||
class ThreadSafeDictionary<K, V> : IDictionary<K, V> | ||
{ | ||
Dictionary<K, V> dic = new Dictionary<K, V>(); | ||
|
||
public Dictionary<K,V> InnerDictionary { get { return dic; } } | ||
public V this[K key] | ||
{ | ||
get | ||
{ | ||
return dic[key]; | ||
} | ||
|
||
set | ||
{ | ||
lock(dic) | ||
dic[key] = value; | ||
} | ||
} | ||
|
||
public int Count | ||
{ | ||
get | ||
{ | ||
lock(dic) | ||
return dic.Count; | ||
} | ||
} | ||
|
||
public bool IsReadOnly | ||
{ | ||
get | ||
{ | ||
lock(dic) | ||
return IsReadOnly; | ||
} | ||
} | ||
|
||
public ICollection<K> Keys | ||
{ | ||
get | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public ICollection<V> Values | ||
{ | ||
get | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public void Add(KeyValuePair<K, V> item) | ||
{ | ||
lock (dic) | ||
dic.Add(item.Key, item.Value); | ||
} | ||
|
||
public void Add(K key, V value) | ||
{ | ||
lock(dic) | ||
dic.Add(key, value); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
lock(dic) | ||
dic.Clear(); | ||
} | ||
|
||
public bool Contains(KeyValuePair<K, V> item) | ||
{ | ||
return dic.ContainsKey(item.Key); | ||
} | ||
|
||
public bool ContainsKey(K key) | ||
{ | ||
return dic.ContainsKey(key); | ||
} | ||
|
||
public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IEnumerator<KeyValuePair<K, V>> GetEnumerator() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public bool Remove(KeyValuePair<K, V> item) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public bool Remove(K key) | ||
{ | ||
lock(dic) | ||
return dic.Remove(key); | ||
} | ||
|
||
public bool TryGetValue(K key, out V value) | ||
{ | ||
return dic.TryGetValue(key, out value); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.