diff options
author | Christopher R. Palmer <crpalmer@gmail.com> | 2016-12-02 16:04:07 -0500 |
---|---|---|
committer | Michael Bestas <mikeioannina@gmail.com> | 2016-12-31 23:43:06 +0200 |
commit | 773e16b98cb8ca2000eaeaf49f239f39ac51d562 (patch) | |
tree | bdac0298c77ad1dc6d0e3580c7b6382995c80e9e | |
parent | 24ef6fe4e98363a97d0a729673d27ffebaed7cb2 (diff) | |
download | art-cm-14.1_old.tar.gz art-cm-14.1_old.tar.bz2 art-cm-14.1_old.zip |
dex2oat: Use CLOCK_MONOTONIC, not REALTIME for a watchdog!staging/cm-14.1-cafrebasecm-14.1_old
Prior to this commit, dex2oat was using the realtime clock to determine
whether or not to kill dex2oat when it ran too long.
This causes problems when the time on the system changes during dex2oat.
In particular, on victara, the time daemon would start up during dex2oat
of boot.art which causes that critical dex2oat operation to fail on boot.
Change-Id: I8be1e09479006bf0692bb9b29f3eab2d140096bb
dex2oat: Fix compilation of host binary on Mac due to watchdog fix
Change-Id: I2628349ff56fdcde86499ef9b0b9b15d382dbbf6
-rw-r--r-- | dex2oat/dex2oat.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 729d712a54..d7a0266bf6 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -80,6 +80,13 @@ #include "well_known_classes.h" #include "zip_archive.h" +#if !defined(__APPLE__) +// Apple doesn't have CLOCK_MONOTONIC +#define WATCHDOG_CLOCK CLOCK_MONOTONIC +#else +#define WATCHDOG_CLOCK CLOCK_REALTIME +#endif + namespace art { static constexpr size_t kDefaultMinDexFilesForSwap = 2; @@ -413,7 +420,13 @@ class WatchDog { shutting_down_ = false; const char* reason = "dex2oat watch dog thread startup"; CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_init, (&mutex_, nullptr), reason); - CHECK_WATCH_DOG_PTHREAD_CALL(pthread_cond_init, (&cond_, nullptr), reason); + CHECK_WATCH_DOG_PTHREAD_CALL(pthread_condattr_init, (&condattr_), reason); +#if !defined(__APPLE__) + // Apple doesn't have CLOCK_MONOTONIC or pthread_condattr_setclock. + CHECK_WATCH_DOG_PTHREAD_CALL(pthread_condattr_setclock, (&condattr_, WATCHDOG_CLOCK), reason); +#endif + CHECK_WATCH_DOG_PTHREAD_CALL(pthread_cond_init, (&cond_, &condattr_), reason); + CHECK_WATCH_DOG_PTHREAD_CALL(pthread_condattr_destroy, (&condattr_), reason); CHECK_WATCH_DOG_PTHREAD_CALL(pthread_attr_init, (&attr_), reason); CHECK_WATCH_DOG_PTHREAD_CALL(pthread_create, (&pthread_, &attr_, &CallBack, this), reason); CHECK_WATCH_DOG_PTHREAD_CALL(pthread_attr_destroy, (&attr_), reason); @@ -456,7 +469,7 @@ class WatchDog { // large. constexpr int64_t multiplier = kVerifyObjectSupport > kVerifyObjectModeFast ? 100 : 1; timespec timeout_ts; - InitTimeSpec(true, CLOCK_REALTIME, multiplier * kWatchDogTimeoutSeconds * 1000, 0, &timeout_ts); + InitTimeSpec(true, WATCHDOG_CLOCK, multiplier * kWatchDogTimeoutSeconds * 1000, 0, &timeout_ts); const char* reason = "dex2oat watch dog thread waiting"; CHECK_WATCH_DOG_PTHREAD_CALL(pthread_mutex_lock, (&mutex_), reason); while (!shutting_down_) { @@ -486,6 +499,7 @@ class WatchDog { bool shutting_down_; // TODO: Switch to Mutex when we can guarantee it won't prevent shutdown in error cases. pthread_mutex_t mutex_; + pthread_condattr_t condattr_; pthread_cond_t cond_; pthread_attr_t attr_; pthread_t pthread_; |