1
1
/**
2
2
* Logback: the reliable, generic, fast and flexible logging framework.
3
- * Copyright (C) 1999-2015 , QOS.ch. All rights reserved.
3
+ * Copyright (C) 1999-2024 , QOS.ch. All rights reserved.
4
4
*
5
5
* This program and the accompanying materials are dual-licensed under
6
6
* either the terms of the Eclipse Public License v1.0 as published by
15
15
16
16
import java .util .ArrayList ;
17
17
import java .util .List ;
18
+ import java .util .concurrent .atomic .AtomicInteger ;
18
19
19
20
import ch .qos .logback .core .helpers .CyclicBuffer ;
20
21
import ch .qos .logback .core .spi .LogbackLock ;
@@ -28,14 +29,14 @@ public class BasicStatusManager implements StatusManager {
28
29
public static final int MAX_HEADER_COUNT = 150 ;
29
30
public static final int TAIL_SIZE = 150 ;
30
31
31
- int count = 0 ;
32
+ final AtomicInteger count = new AtomicInteger () ;
32
33
33
34
// protected access was requested in http://jira.qos.ch/browse/LBCORE-36
34
35
final protected List <Status > statusList = new ArrayList <Status >();
35
36
final protected CyclicBuffer <Status > tailBuffer = new CyclicBuffer <Status >(TAIL_SIZE );
36
37
final protected LogbackLock statusListLock = new LogbackLock ();
37
38
38
- int level = Status .INFO ;
39
+ final AtomicInteger level = new AtomicInteger ( Status .INFO ) ;
39
40
40
41
// protected access was requested in http://jira.qos.ch/browse/LBCORE-36
41
42
final protected List <StatusListener > statusListenerList = new ArrayList <StatusListener >();
@@ -57,10 +58,15 @@ public void add(Status newStatus) {
57
58
// LBCORE-72: fire event before the count check
58
59
fireStatusAddEvent (newStatus );
59
60
60
- count ++;
61
- if (newStatus .getLevel () > level ) {
62
- level = newStatus .getLevel ();
63
- }
61
+ count .getAndIncrement ();
62
+ int currentLevel ;
63
+ int newLevel = newStatus .getLevel ();
64
+ do {
65
+ currentLevel = level .get ();
66
+ if (newLevel <= currentLevel ) {
67
+ break ;
68
+ }
69
+ } while (!level .compareAndSet (currentLevel , newLevel ));
64
70
65
71
synchronized (statusListLock ) {
66
72
if (statusList .size () < MAX_HEADER_COUNT ) {
@@ -90,18 +96,18 @@ private void fireStatusAddEvent(Status status) {
90
96
91
97
public void clear () {
92
98
synchronized (statusListLock ) {
93
- count = 0 ;
99
+ count . set ( 0 ) ;
94
100
statusList .clear ();
95
101
tailBuffer .clear ();
96
102
}
97
103
}
98
104
99
105
public int getLevel () {
100
- return level ;
106
+ return level . get () ;
101
107
}
102
108
103
109
public int getCount () {
104
- return count ;
110
+ return count . get () ;
105
111
}
106
112
107
113
/**
0 commit comments