You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2016/10/05 20:10:39 UTC

[6/6] incubator-impala git commit: IMPALA-4246: SleepForMs() utility function has undefined behavior for > 1s

IMPALA-4246: SleepForMs() utility function has undefined behavior for > 1s

Our SleepForMs() function relied on usleep() which sleeps for 'n'
microseconds. However, the manpage for usleep() specifies that this
may not work for values > 1000000 us (or 1s).

This patch removes the use of usleep() and uses
std::this_thread::sleep_for() instead, which was introduced with C++11.

Change-Id: I06c55b1be287b264e7601c9c89788ae5929571cf
Reviewed-on: http://gerrit.cloudera.org:8080/4622
Reviewed-by: Sailesh Mukil <sa...@cloudera.com>
Tested-by: Internal Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/3be113cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/3be113cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/3be113cb

Branch: refs/heads/master
Commit: 3be113cb9fd6460a80b8198a50f3619c4b9539a2
Parents: 112ff68
Author: Sailesh Mukil <sa...@cloudera.com>
Authored: Tue Oct 4 15:31:58 2016 -0700
Committer: Internal Jenkins <cl...@gerrit.cloudera.org>
Committed: Wed Oct 5 03:29:03 2016 +0000

----------------------------------------------------------------------
 be/src/util/time.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/3be113cb/be/src/util/time.cc
----------------------------------------------------------------------
diff --git a/be/src/util/time.cc b/be/src/util/time.cc
index b7d31ad..e6530de 100644
--- a/be/src/util/time.cc
+++ b/be/src/util/time.cc
@@ -15,13 +15,14 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#include <unistd.h>
+#include <chrono>
+#include <thread>
 
 #include "util/time.h"
 
 using namespace impala;
+using namespace std;
 
 void impala::SleepForMs(const int64_t duration_ms) {
-  // TODO: Replace with sleep_for when we upgrade to recent boost / C++11?
-  usleep(duration_ms * 1000L);
+  this_thread::sleep_for(chrono::milliseconds(duration_ms));
 }