Make LifecycleTracer thread-safe
The real world may expose the buffers to concurrent accesses even when this is not supposed to be supported.
This commit is contained in:
parent
2f9aabc915
commit
f460c732d0
@ -83,10 +83,12 @@ abstract class LifecycleTracer {
|
||||
}
|
||||
|
||||
void addTrace(Trace trace) {
|
||||
if (traces.size() == MAX_TRACE_POINTS) {
|
||||
traces.pollFirst();
|
||||
synchronized (traces) {
|
||||
if (traces.size() == MAX_TRACE_POINTS) {
|
||||
traces.pollFirst();
|
||||
}
|
||||
traces.addLast(trace);
|
||||
}
|
||||
traces.addLast(trace);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,9 +120,11 @@ abstract class LifecycleTracer {
|
||||
|
||||
@Override
|
||||
<E extends Throwable> E attachTrace(E throwable) {
|
||||
long timestamp = System.nanoTime();
|
||||
for (Trace trace : traces) {
|
||||
trace.attach(throwable, timestamp);
|
||||
synchronized (traces) {
|
||||
long timestamp = System.nanoTime();
|
||||
for (Trace trace : traces) {
|
||||
trace.attach(throwable, timestamp);
|
||||
}
|
||||
}
|
||||
return throwable;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user