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
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja;
|
||||||
|
@ -217,7 +217,10 @@ public class SimEventCentral {
|
||||||
|
|
||||||
/* We may have to remove some events now */
|
/* We may have to remove some events now */
|
||||||
while (logOutputEvents.size() > logOutputBufferSize-1) {
|
while (logOutputEvents.size() > logOutputBufferSize-1) {
|
||||||
LogOutputEvent removed = logOutputEvents.pollFirst();
|
LogOutputEvent removed;
|
||||||
|
synchronized (logOutputEvents) {
|
||||||
|
removed = logOutputEvents.pollFirst();
|
||||||
|
}
|
||||||
if (removed == null) {
|
if (removed == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -225,11 +228,12 @@ public class SimEventCentral {
|
||||||
l.removedLogOutput(removed);
|
l.removedLogOutput(removed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store log output, and notify listeners */
|
/* Store log output, and notify listeners */
|
||||||
LogOutputEvent ev =
|
LogOutputEvent ev = new LogOutputEvent(mote, simulation.getSimulationTime(), msg);
|
||||||
new LogOutputEvent(mote, simulation.getSimulationTime(), msg);
|
synchronized (logOutputEvents) {
|
||||||
logOutputEvents.add(ev);
|
logOutputEvents.add(ev);
|
||||||
|
}
|
||||||
for (LogOutputListener l: logOutputListeners) {
|
for (LogOutputListener l: logOutputListeners) {
|
||||||
l.newLogOutput(ev);
|
l.newLogOutput(ev);
|
||||||
}
|
}
|
||||||
|
@ -269,8 +273,11 @@ public class SimEventCentral {
|
||||||
logOutputEvents.clear();
|
logOutputEvents.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogOutputEvent[] getLogOutputHistory() {
|
public LogOutputEvent[] getLogOutputHistory() {
|
||||||
return logOutputEvents.toArray(new LogOutputEvent[0]);
|
synchronized (logOutputEvents) {
|
||||||
|
return logOutputEvents.toArray(new LogOutputEvent[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public int getLogOutputBufferSize() {
|
public int getLogOutputBufferSize() {
|
||||||
return logOutputBufferSize;
|
return logOutputBufferSize;
|
||||||
|
|
Loading…
Reference in a new issue