Get rid of Utils::sleep

Replace with std::this_thread::sleep_for()

Change-Id: I3a02fa6d4fc1b41d8d7b01bb3ba0342ce49b8e61
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Orgad Shaneh
2016-09-10 22:54:58 +03:00
committed by Orgad Shaneh
parent 8edda219d9
commit 88aa956bb7
5 changed files with 4 additions and 84 deletions

View File

@@ -1,43 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Orgad Shaneh <orgads@gmail.com>.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "sleep.h"
#ifdef Q_OS_WIN
#include <windows.h>
#else
#include <time.h>
#include <unistd.h>
#endif
void Utils::sleep(int msec)
{
#ifdef Q_OS_WIN
::Sleep(msec);
#else
struct timespec ts = { msec / 1000, (msec % 1000) * 1000000 };
::nanosleep(&ts, NULL);
#endif
}

View File

@@ -1,34 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 Orgad Shaneh <orgads@gmail.com>.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "utils_global.h"
namespace Utils {
void QTCREATOR_UTILS_EXPORT sleep(int msec);
}

View File

@@ -72,7 +72,6 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/json.cpp \ $$PWD/json.cpp \
$$PWD/portlist.cpp \ $$PWD/portlist.cpp \
$$PWD/appmainwindow.cpp \ $$PWD/appmainwindow.cpp \
$$PWD/sleep.cpp \
$$PWD/basetreeview.cpp \ $$PWD/basetreeview.cpp \
$$PWD/qtcassert.cpp \ $$PWD/qtcassert.cpp \
$$PWD/elfreader.cpp \ $$PWD/elfreader.cpp \
@@ -173,7 +172,6 @@ HEADERS += \
$$PWD/runextensions.h \ $$PWD/runextensions.h \
$$PWD/portlist.h \ $$PWD/portlist.h \
$$PWD/appmainwindow.h \ $$PWD/appmainwindow.h \
$$PWD/sleep.h \
$$PWD/basetreeview.h \ $$PWD/basetreeview.h \
$$PWD/elfreader.h \ $$PWD/elfreader.h \
$$PWD/bracematcher.h \ $$PWD/bracematcher.h \

View File

@@ -190,8 +190,6 @@ Project {
"shellcommandpage.cpp", "shellcommandpage.cpp",
"shellcommandpage.h", "shellcommandpage.h",
"sizedarray.h", "sizedarray.h",
"sleep.cpp",
"sleep.h",
"smallstring.h", "smallstring.h",
"smallstringiterator.h", "smallstringiterator.h",
"smallstringio.h", "smallstringio.h",

View File

@@ -52,7 +52,6 @@
#include <utils/persistentsettings.h> #include <utils/persistentsettings.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/runextensions.h> #include <utils/runextensions.h>
#include <utils/sleep.h>
#include <utils/synchronousprocess.h> #include <utils/synchronousprocess.h>
#include <QApplication> #include <QApplication>
@@ -64,7 +63,9 @@
#include <QStringList> #include <QStringList>
#include <QTcpSocket> #include <QTcpSocket>
#include <chrono>
#include <functional> #include <functional>
#include <thread>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
@@ -825,7 +826,7 @@ bool AndroidConfig::waitForBooted(const QString &serialNumber, const QFutureInte
if (hasFinishedBooting(serialNumber)) { if (hasFinishedBooting(serialNumber)) {
return true; return true;
} else { } else {
Utils::sleep(2000); std::this_thread::sleep_for(std::chrono::seconds(2));
if (!isConnected(serialNumber)) // device was disconnected if (!isConnected(serialNumber)) // device was disconnected
return false; return false;
} }
@@ -844,7 +845,7 @@ QString AndroidConfig::waitForAvd(const QString &avdName, const QFutureInterface
serialNumber = findAvd(avdName); serialNumber = findAvd(avdName);
if (!serialNumber.isEmpty()) if (!serialNumber.isEmpty())
return waitForBooted(serialNumber, fi) ? serialNumber : QString(); return waitForBooted(serialNumber, fi) ? serialNumber : QString();
Utils::sleep(2000); std::this_thread::sleep_for(std::chrono::seconds(2));
} }
return QString(); return QString();
} }