-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequestChecker.cs
72 lines (60 loc) · 1.58 KB
/
RequestChecker.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
using System.Collections.Generic;
using System.Threading;
public class RequestChecker
{
public List<string> requestUUIDs;
public ResourceSemaphore semaphore;
public RequestChecker()
{
this.requestUUIDs = new List<string>();
this.semaphore = new ResourceSemaphore();
}
public void AddRequestUUID(string requestUUID)
{
while (semaphore.IsResourceNotAvailable())
{
Thread.Sleep(250);
}
if (semaphore.IsResourceAvailable())
{
semaphore.LockResource();
requestUUIDs.Add(requestUUID);
semaphore.UnlockResource();
}
}
public void DeleteRequestUUID(string requestUUID)
{
while (semaphore.IsResourceNotAvailable())
{
Thread.Sleep(250);
}
if (semaphore.IsResourceAvailable())
{
semaphore.LockResource();
requestUUIDs.Remove(requestUUID);
semaphore.UnlockResource();
}
}
public bool IsRequestUUIDAdded(string requestUUID)
{
bool exists = false;
while (semaphore.IsResourceNotAvailable())
{
Thread.Sleep(250);
}
if (semaphore.IsResourceAvailable())
{
semaphore.LockResource();
foreach (string uuid in requestUUIDs)
{
if (uuid.Equals(requestUUID))
{
exists = true;
break;
}
}
semaphore.UnlockResource();
}
return exists;
}
}