forked from backtrace-labs/backtrace-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBacktraceThreadWatcher.java
More file actions
109 lines (96 loc) · 2.5 KB
/
BacktraceThreadWatcher.java
File metadata and controls
109 lines (96 loc) · 2.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package backtrace.io.backtrace_unity_android_plugin;
/**
* This class is a representation of the state of the thread,
* the user's thread has access to one counter and BacktraceWatchdog to the other.
* By comparing the values of the counters it is possible to
* determine whether the thread has been hanged.
*/
public class BacktraceThreadWatcher {
private int counter;
private int privateCounter;
private int timeout;
private int delay;
private long lastTimestamp;
private boolean active;
/**
* Thread watcher which is using to monitoring thread state
*
* @param timeout maximum time in milliseconds after which should check if the main thread is not hanged
* @param delay delay in milliseconds from which we should monitor the thread
*/
BacktraceThreadWatcher(int timeout, int delay) {
this.timeout = timeout;
this.delay = delay;
setActive(true);
}
/**
* @return timeout value in milliseconds
*/
int getTimeout() {
return timeout;
}
/**
* @return delay value in milliseconds
*/
int getDelay() {
return delay;
}
/**
* @return last timestamp when the thread was checked
*/
long getLastTimestamp() {
return lastTimestamp;
}
/**
* @param lastTimestamp new value of last timestamp when thread was checked
*/
void setLastTimestamp(long lastTimestamp) {
this.lastTimestamp = lastTimestamp;
}
/**
* Check is watcher for thread is active
*
* @return is thread watcher active
*/
synchronized boolean isActive() {
return active;
}
/**
* Set status of thread watcher
*
* @param active if active value is false thread is not observed
*/
synchronized void setActive(boolean active) {
this.active = active;
}
/**
* Increase thread private counter by 1
*/
void tickPrivateCounter() {
privateCounter++;
}
/**
* @return thread private counter
*/
int getPrivateCounter() {
return privateCounter;
}
/**
* @param privateCounter new value of private counter
*/
void setPrivateCounter(int privateCounter) {
this.privateCounter = privateCounter;
}
/**
* @return thread counter
*/
synchronized int getCounter() {
return counter;
}
/**
* Increase thread counter by 1
*/
public synchronized void tickCounter() {
counter++;
}
}