6900441: PlatformEvent.park(millis) on Linux could still be affected by changes to the time-of-day clock

Associate CLOCK_MONOTONIC with the pthread_cond_t objects used for relative timed waits

Reviewed-by: dcubed, shade
This commit is contained in:
David Holmes 2013-09-16 07:38:13 -04:00
parent 59a89ae1e1
commit 139c3e6621
2 changed files with 128 additions and 45 deletions

View file

@ -221,6 +221,13 @@ class Linux {
static jlong fast_thread_cpu_time(clockid_t clockid);
// pthread_cond clock suppport
private:
static pthread_condattr_t _condattr[1];
public:
static pthread_condattr_t* condAttr() { return _condattr; }
// Stack repair handling
// none present
@ -295,7 +302,7 @@ class PlatformEvent : public CHeapObj<mtInternal> {
public:
PlatformEvent() {
int status;
status = pthread_cond_init (_cond, NULL);
status = pthread_cond_init (_cond, os::Linux::condAttr());
assert_status(status == 0, status, "cond_init");
status = pthread_mutex_init (_mutex, NULL);
assert_status(status == 0, status, "mutex_init");
@ -310,14 +317,19 @@ class PlatformEvent : public CHeapObj<mtInternal> {
void park () ;
void unpark () ;
int TryPark () ;
int park (jlong millis) ;
int park (jlong millis) ; // relative timed-wait only
void SetAssociation (Thread * a) { _Assoc = a ; }
} ;
class PlatformParker : public CHeapObj<mtInternal> {
protected:
enum {
REL_INDEX = 0,
ABS_INDEX = 1
};
int _cur_index; // which cond is in use: -1, 0, 1
pthread_mutex_t _mutex [1] ;
pthread_cond_t _cond [1] ;
pthread_cond_t _cond [2] ; // one for relative times and one for abs.
public: // TODO-FIXME: make dtor private
~PlatformParker() { guarantee (0, "invariant") ; }
@ -325,10 +337,13 @@ class PlatformParker : public CHeapObj<mtInternal> {
public:
PlatformParker() {
int status;
status = pthread_cond_init (_cond, NULL);
assert_status(status == 0, status, "cond_init");
status = pthread_cond_init (&_cond[REL_INDEX], os::Linux::condAttr());
assert_status(status == 0, status, "cond_init rel");
status = pthread_cond_init (&_cond[ABS_INDEX], NULL);
assert_status(status == 0, status, "cond_init abs");
status = pthread_mutex_init (_mutex, NULL);
assert_status(status == 0, status, "mutex_init");
_cur_index = -1; // mark as unused
}
};