diff --git a/src/train/Section.java b/src/train/Section.java index 25d2f03c01efc2608aba91e13577b310209bdfd2..7e77a97614ffc9fe2bc9973fd3576cf607f6da94 100644 --- a/src/train/Section.java +++ b/src/train/Section.java @@ -8,23 +8,23 @@ package train; * @author Philippe Tanguy <philippe.tanguy@imt-atlantique.fr> */ public class Section extends Element { - private Train currentTrain = null; + private int currentTrain = 0; public Section(String name) { super(name); - this.currentTrain = null; + this.currentTrain = 0; } - public synchronized void enterSection(Train t) throws InterruptedException { - while (currentTrain != null) { // Attendre que la section soit libre + public synchronized void enterSection() throws InterruptedException { + while (currentTrain != 0) { // Attendre que la section soit libre wait(); } - currentTrain = t; + currentTrain = 1; } - public synchronized void leaveSection(Train t) { - if (currentTrain == t) { - currentTrain = null; + public synchronized void leaveSection() { + if (currentTrain == 1) { + currentTrain = 0; notifyAll(); // Réveille les trains en attente } } diff --git a/src/train/Station.java b/src/train/Station.java index 53eeb4a5b4499f7993b9d148128d6f87e6f96b12..627baaae67477d6f3e849dbcb3d8e38ce66d01bd 100644 --- a/src/train/Station.java +++ b/src/train/Station.java @@ -20,14 +20,14 @@ public class Station extends Element { this.currentTrain = 0; } - public synchronized void enterStation(Train t) throws InterruptedException { + public synchronized void enterStation() throws InterruptedException { while (currentTrain >= size) { // Si la gare est pleine, attendre wait(); } currentTrain++; } - public synchronized void leaveStation(Train t) { + public synchronized void leaveStation() { currentTrain--; notifyAll(); // Réveille les trains en attente }