comparison src/os/linux/vm/os_linux.hpp @ 12211:2e6938dd68f2

6900441: PlatformEvent.park(millis) on Linux could still be affected by changes to the time-of-day clock Summary: Associate CLOCK_MONOTONIC with the pthread_cond_t objects used for relative timed waits Reviewed-by: dcubed, shade
author dholmes
date Mon, 16 Sep 2013 07:38:13 -0400
parents 0d59407e7e09
children b0133e4187d3 6c9332549827
comparison
equal deleted inserted replaced
12210:b135b600a66c 12211:2e6938dd68f2
218 static bool supports_fast_thread_cpu_time() { 218 static bool supports_fast_thread_cpu_time() {
219 return _supports_fast_thread_cpu_time; 219 return _supports_fast_thread_cpu_time;
220 } 220 }
221 221
222 static jlong fast_thread_cpu_time(clockid_t clockid); 222 static jlong fast_thread_cpu_time(clockid_t clockid);
223
224 // pthread_cond clock suppport
225 private:
226 static pthread_condattr_t _condattr[1];
227
228 public:
229 static pthread_condattr_t* condAttr() { return _condattr; }
223 230
224 // Stack repair handling 231 // Stack repair handling
225 232
226 // none present 233 // none present
227 234
293 ~PlatformEvent() { guarantee (0, "invariant") ; } 300 ~PlatformEvent() { guarantee (0, "invariant") ; }
294 301
295 public: 302 public:
296 PlatformEvent() { 303 PlatformEvent() {
297 int status; 304 int status;
298 status = pthread_cond_init (_cond, NULL); 305 status = pthread_cond_init (_cond, os::Linux::condAttr());
299 assert_status(status == 0, status, "cond_init"); 306 assert_status(status == 0, status, "cond_init");
300 status = pthread_mutex_init (_mutex, NULL); 307 status = pthread_mutex_init (_mutex, NULL);
301 assert_status(status == 0, status, "mutex_init"); 308 assert_status(status == 0, status, "mutex_init");
302 _Event = 0 ; 309 _Event = 0 ;
303 _nParked = 0 ; 310 _nParked = 0 ;
308 void reset() { _Event = 0 ; } 315 void reset() { _Event = 0 ; }
309 int fired() { return _Event; } 316 int fired() { return _Event; }
310 void park () ; 317 void park () ;
311 void unpark () ; 318 void unpark () ;
312 int TryPark () ; 319 int TryPark () ;
313 int park (jlong millis) ; 320 int park (jlong millis) ; // relative timed-wait only
314 void SetAssociation (Thread * a) { _Assoc = a ; } 321 void SetAssociation (Thread * a) { _Assoc = a ; }
315 } ; 322 } ;
316 323
317 class PlatformParker : public CHeapObj<mtInternal> { 324 class PlatformParker : public CHeapObj<mtInternal> {
318 protected: 325 protected:
326 enum {
327 REL_INDEX = 0,
328 ABS_INDEX = 1
329 };
330 int _cur_index; // which cond is in use: -1, 0, 1
319 pthread_mutex_t _mutex [1] ; 331 pthread_mutex_t _mutex [1] ;
320 pthread_cond_t _cond [1] ; 332 pthread_cond_t _cond [2] ; // one for relative times and one for abs.
321 333
322 public: // TODO-FIXME: make dtor private 334 public: // TODO-FIXME: make dtor private
323 ~PlatformParker() { guarantee (0, "invariant") ; } 335 ~PlatformParker() { guarantee (0, "invariant") ; }
324 336
325 public: 337 public:
326 PlatformParker() { 338 PlatformParker() {
327 int status; 339 int status;
328 status = pthread_cond_init (_cond, NULL); 340 status = pthread_cond_init (&_cond[REL_INDEX], os::Linux::condAttr());
329 assert_status(status == 0, status, "cond_init"); 341 assert_status(status == 0, status, "cond_init rel");
342 status = pthread_cond_init (&_cond[ABS_INDEX], NULL);
343 assert_status(status == 0, status, "cond_init abs");
330 status = pthread_mutex_init (_mutex, NULL); 344 status = pthread_mutex_init (_mutex, NULL);
331 assert_status(status == 0, status, "mutex_init"); 345 assert_status(status == 0, status, "mutex_init");
346 _cur_index = -1; // mark as unused
332 } 347 }
333 }; 348 };
334 349
335 #endif // OS_LINUX_VM_OS_LINUX_HPP 350 #endif // OS_LINUX_VM_OS_LINUX_HPP