synchronizing access to log list
This commit is contained in:
parent
0ec8d499e4
commit
e4c3ac8125
1 changed files with 14 additions and 7 deletions
|
@ -24,7 +24,7 @@
|
|||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: SimEventCentral.java,v 1.3 2009/12/07 11:06:08 fros4943 Exp $
|
||||
* $Id: SimEventCentral.java,v 1.4 2010/03/26 09:12:20 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja;
|
||||
|
@ -217,7 +217,10 @@ public class SimEventCentral {
|
|||
|
||||
/* We may have to remove some events now */
|
||||
while (logOutputEvents.size() > logOutputBufferSize-1) {
|
||||
LogOutputEvent removed = logOutputEvents.pollFirst();
|
||||
LogOutputEvent removed;
|
||||
synchronized (logOutputEvents) {
|
||||
removed = logOutputEvents.pollFirst();
|
||||
}
|
||||
if (removed == null) {
|
||||
break;
|
||||
}
|
||||
|
@ -225,11 +228,12 @@ public class SimEventCentral {
|
|||
l.removedLogOutput(removed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Store log output, and notify listeners */
|
||||
LogOutputEvent ev =
|
||||
new LogOutputEvent(mote, simulation.getSimulationTime(), msg);
|
||||
logOutputEvents.add(ev);
|
||||
LogOutputEvent ev = new LogOutputEvent(mote, simulation.getSimulationTime(), msg);
|
||||
synchronized (logOutputEvents) {
|
||||
logOutputEvents.add(ev);
|
||||
}
|
||||
for (LogOutputListener l: logOutputListeners) {
|
||||
l.newLogOutput(ev);
|
||||
}
|
||||
|
@ -269,8 +273,11 @@ public class SimEventCentral {
|
|||
logOutputEvents.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public LogOutputEvent[] getLogOutputHistory() {
|
||||
return logOutputEvents.toArray(new LogOutputEvent[0]);
|
||||
synchronized (logOutputEvents) {
|
||||
return logOutputEvents.toArray(new LogOutputEvent[0]);
|
||||
}
|
||||
}
|
||||
public int getLogOutputBufferSize() {
|
||||
return logOutputBufferSize;
|
||||
|
|
Loading…
Reference in a new issue