-
Notifications
You must be signed in to change notification settings - Fork 0
/
SafeList.cs
73 lines (64 loc) · 883 Bytes
/
SafeList.cs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
namespace Terralite
{
public class SafeList<T>
{
private List<T> list;
private object listLock;
public SafeList()
{
list = new List<T>();
listLock = new object();
}
public int Count
{
get { lock (listLock) { return list.Count; } }
}
public void Add(T obj)
{
lock (listLock)
{
list.Add(obj);
}
}
public void AddRange(IEnumerable<T> range)
{
lock (listLock)
{
list.AddRange(range);
}
}
public void Clear()
{
lock (listLock)
{
list.Clear();
}
}
public void Remove(T obj)
{
lock (listLock)
{
list.Remove(obj);
}
}
public void RemoveAt(int index)
{
lock (listLock)
{
list.RemoveAt(index);
}
}
public T this[int index]
{
get
{
lock (listLock)
{
return list[index];
}
}
}
}
}