forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcurrentDictionary.cs
More file actions
57 lines (47 loc) · 1.24 KB
/
Copy pathConcurrentDictionary.cs
File metadata and controls
57 lines (47 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Threading;
namespace UnityEngine.CSSLayout
{
internal class LockDictionary<TKey, TValue>
{
object _cacheLock = new object();
Dictionary<TKey, TValue> _cacheItemDictionary = new Dictionary<TKey, TValue>();
public void Set(TKey key, TValue value)
{
lock (_cacheLock)
{
_cacheItemDictionary[key] = value;
}
}
public bool TryGetValue(TKey key, out TValue cacheItem)
{
bool found;
lock (_cacheLock)
{
found = _cacheItemDictionary.TryGetValue(key, out cacheItem);
}
if (!found)
{
cacheItem = default(TValue);
}
return found;
}
public bool ContainsKey(TKey key)
{
bool found = false;
lock (_cacheLock)
{
found = _cacheItemDictionary.ContainsKey(key);
}
return found;
}
public void Remove(TKey key)
{
lock (_cacheLock)
{
_cacheItemDictionary.Remove(key);
}
}
}
}