88 int PeriodicTask::time_to_wait() {
89 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
90 NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
91
92 if (_num_tasks == 0) {
93 return 0; // sleep until shutdown or a task is enrolled
94 }
95
96 int delay = _tasks[0]->time_to_next_interval();
97 for (int index = 1; index < _num_tasks; index++) {
98 delay = MIN2(delay, _tasks[index]->time_to_next_interval());
99 }
100 return delay;
101 }
102
103
104 PeriodicTask::PeriodicTask(size_t interval_time) :
105 _counter(0), _interval((int) interval_time) {
106 // Sanity check the interval time
107 assert(_interval >= PeriodicTask::min_interval &&
108 _interval <= PeriodicTask::max_interval &&
109 _interval % PeriodicTask::interval_gran == 0,
110 "improper PeriodicTask interval time");
111 }
112
113 PeriodicTask::~PeriodicTask() {
114 disenroll();
115 }
116
117 /* enroll could be called from a JavaThread, so we have to check for
118 * safepoint when taking the lock to avoid deadlocking */
119 void PeriodicTask::enroll() {
120 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
121 NULL : PeriodicTask_lock);
122
123 if (_num_tasks == PeriodicTask::max_tasks) {
124 fatal("Overflow in PeriodicTask table");
125 }
126 _tasks[_num_tasks++] = this;
127
128 WatcherThread* thread = WatcherThread::watcher_thread();
|
88 int PeriodicTask::time_to_wait() {
89 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
90 NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
91
92 if (_num_tasks == 0) {
93 return 0; // sleep until shutdown or a task is enrolled
94 }
95
96 int delay = _tasks[0]->time_to_next_interval();
97 for (int index = 1; index < _num_tasks; index++) {
98 delay = MIN2(delay, _tasks[index]->time_to_next_interval());
99 }
100 return delay;
101 }
102
103
104 PeriodicTask::PeriodicTask(size_t interval_time) :
105 _counter(0), _interval((int) interval_time) {
106 // Sanity check the interval time
107 assert(_interval >= PeriodicTask::min_interval &&
108 _interval % PeriodicTask::interval_gran == 0,
109 "improper PeriodicTask interval time");
110 }
111
112 PeriodicTask::~PeriodicTask() {
113 disenroll();
114 }
115
116 /* enroll could be called from a JavaThread, so we have to check for
117 * safepoint when taking the lock to avoid deadlocking */
118 void PeriodicTask::enroll() {
119 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
120 NULL : PeriodicTask_lock);
121
122 if (_num_tasks == PeriodicTask::max_tasks) {
123 fatal("Overflow in PeriodicTask table");
124 }
125 _tasks[_num_tasks++] = this;
126
127 WatcherThread* thread = WatcherThread::watcher_thread();
|