src/share/vm/runtime/task.hpp

changeset 4250
c284cf4781f0
parent 4153
b9a9ed0f8eeb
child 6876
710a3c8b516e
     1.1 --- a/src/share/vm/runtime/task.hpp	Mon Nov 05 13:55:31 2012 -0800
     1.2 +++ b/src/share/vm/runtime/task.hpp	Thu Oct 04 14:55:57 2012 +0200
     1.3 @@ -49,12 +49,12 @@
     1.4    static int num_tasks()   { return _num_tasks; }
     1.5  
     1.6   private:
     1.7 -  size_t _counter;
     1.8 -  const size_t _interval;
     1.9 +  int _counter;
    1.10 +  const int _interval;
    1.11  
    1.12    static int _num_tasks;
    1.13    static PeriodicTask* _tasks[PeriodicTask::max_tasks];
    1.14 -  static void real_time_tick(size_t delay_time);
    1.15 +  static void real_time_tick(int delay_time);
    1.16  
    1.17  #ifndef PRODUCT
    1.18    static elapsedTimer _timer;                      // measures time between ticks
    1.19 @@ -69,51 +69,36 @@
    1.20    PeriodicTask(size_t interval_time); // interval is in milliseconds of elapsed time
    1.21    ~PeriodicTask();
    1.22  
    1.23 -  // Tells whether is enrolled
    1.24 -  bool is_enrolled() const;
    1.25 -
    1.26    // Make the task active
    1.27 -  // NOTE: this may only be called before the WatcherThread has been started
    1.28 +  // For dynamic enrollment at the time T, the task will execute somewhere
    1.29 +  // between T and T + interval_time.
    1.30    void enroll();
    1.31  
    1.32    // Make the task deactive
    1.33 -  // NOTE: this may only be called either while the WatcherThread is
    1.34 -  // inactive or by a task from within its task() method. One-shot or
    1.35 -  // several-shot tasks may be implemented this way.
    1.36    void disenroll();
    1.37  
    1.38 -  void execute_if_pending(size_t delay_time) {
    1.39 -    _counter += delay_time;
    1.40 -    if (_counter >= _interval) {
    1.41 +  void execute_if_pending(int delay_time) {
    1.42 +    // make sure we don't overflow
    1.43 +    jlong tmp = (jlong) _counter + (jlong) delay_time;
    1.44 +
    1.45 +    if (tmp >= (jlong) _interval) {
    1.46        _counter = 0;
    1.47        task();
    1.48 +    } else {
    1.49 +      _counter += delay_time;
    1.50      }
    1.51    }
    1.52  
    1.53    // Returns how long (time in milliseconds) before the next time we should
    1.54    // execute this task.
    1.55 -  size_t time_to_next_interval() const {
    1.56 +  int time_to_next_interval() const {
    1.57      assert(_interval > _counter,  "task counter greater than interval?");
    1.58      return _interval - _counter;
    1.59    }
    1.60  
    1.61    // Calculate when the next periodic task will fire.
    1.62    // Called by the WatcherThread's run method.
    1.63 -  // This assumes that periodic tasks aren't entering the system
    1.64 -  // dynamically, except for during startup.
    1.65 -  static size_t time_to_wait() {
    1.66 -    if (_num_tasks == 0) {
    1.67 -      // Don't wait any more; shut down the thread since we don't
    1.68 -      // currently support dynamic enrollment.
    1.69 -      return 0;
    1.70 -    }
    1.71 -
    1.72 -    size_t delay = _tasks[0]->time_to_next_interval();
    1.73 -    for (int index = 1; index < _num_tasks; index++) {
    1.74 -      delay = MIN2(delay, _tasks[index]->time_to_next_interval());
    1.75 -    }
    1.76 -    return delay;
    1.77 -  }
    1.78 +  static int time_to_wait();
    1.79  
    1.80    // The task to perform at each period
    1.81    virtual void task() = 0;

mercurial