Exemplo n.º 1
0
  /**
   * The <code>removeNode()</code> method removes a node from this synchronization group, and wakes
   * any nodes that might be waiting on it.
   *
   * @param t the simulator thread to remove from this synchronization group
   */
  public synchronized void removeNode(Simulation.Node t) {
    // don't try to remove a thread that's not here!
    SimulatorThread st = t.getThread();
    if (!threadMap.containsKey(st)) return;
    synchronized (condition) {
      SynchEvent e = (SynchEvent) threadMap.get(st);
      e.removed = true; // just in case the thread is still running, don't let it synch
      if (e.met) meet_count--;

      if (stillWaiting(e.waitSlot)) {
        // if this wait slot hasn't happened yet, we need to decrement wait_count
        // and to decrement the number of waiters in that slot
        e.waitSlot.numWaiters--;
        wait_count--;
      }
      threadMap.remove(e);
      goal--;
      // signal any other threads (and wake waiters as necessary) but don't wait
      signalOthers();
    }
  }
Exemplo n.º 2
0
  protected WaitSlot insertWaiter(SynchEvent event, long time) {
    // get a wait slot for this waiter
    WaitSlot w = getWaitSlot(time);

    // now this thread is officially waiting
    wait_count++;
    // remember the wait slot this waiter is in
    event.waitSlot = w;
    // increment the number of waiters in this slot
    w.numWaiters++;

    return w;
  }