r22698 by jghali - replace sleep/usleep calls by C++11 conformant std::this_thread::sleep_for()

scribus-commit scribus-commit at lists.scribus.net
Wed Sep 19 18:11:08 UTC 2018


Author: jghali
Date: Wed Sep 19 18:11:08 2018
New Revision: 22698

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22698
Log:
replace sleep/usleep calls by C++11 conformant std::this_thread::sleep_for()

Modified:
    trunk/Scribus/scribus/filewatcher.cpp
    trunk/Scribus/scribus/plugins/gettext/docim/docim.cpp
    trunk/Scribus/scribus/upgradechecker.cpp

Modified: trunk/Scribus/scribus/filewatcher.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22698&path=/trunk/Scribus/scribus/filewatcher.cpp
==============================================================================
--- trunk/Scribus/scribus/filewatcher.cpp	(original)
+++ trunk/Scribus/scribus/filewatcher.cpp	Wed Sep 19 18:11:08 2018
@@ -7,13 +7,11 @@
 
 #include "scconfig.h"
 
+#include <chrono>
+#include <thread>
+
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
-
-#if defined(_WIN32) && !defined(usleep)
-#include <windows.h>
-#define usleep(t) Sleep((t > 1000) ? (t / 1000) : 1)
 #endif
 
 #include <QDebug>
@@ -116,7 +114,7 @@
 	m_watchTimer->stop();
 	m_stateFlags |= StopRequested;
 	while ((m_stateFlags & FileCheckRunning))
-		usleep(100);
+		std::this_thread::sleep_for(std::chrono::milliseconds(1));
 	m_stateFlags &= ~StopRequested;
 	m_stateFlags |= TimerStopped;
 }
@@ -206,15 +204,15 @@
 			}
 			else
 			{
-				uint sizeo = it.value().info.size();
-				usleep(100);
+				qint64 sizeo = it.value().info.size();
+				std::this_thread::sleep_for(std::chrono::milliseconds(1));
 				it.value().info.refresh();
-				uint sizen = it.value().info.size();
+				qint64 sizen = it.value().info.size();
 				//					qDebug()<<"Size comparison"<<sizeo<<sizen<<it.key();
 				while (sizen != sizeo)
 				{
 					sizeo = sizen;
-					usleep(100);
+					std::this_thread::sleep_for(std::chrono::milliseconds(1));
 					it.value().info.refresh();
 					sizen = it.value().info.size();
 				}

Modified: trunk/Scribus/scribus/plugins/gettext/docim/docim.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22698&path=/trunk/Scribus/scribus/plugins/gettext/docim/docim.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/docim/docim.cpp	(original)
+++ trunk/Scribus/scribus/plugins/gettext/docim/docim.cpp	Wed Sep 19 18:11:08 2018
@@ -5,11 +5,9 @@
 for which a new license (GPL+exception) is in place.
 */
 
-#include "docim.h"
-#include "gtwriter.h"
-#include "scpaths.h"
-#include "scribusstructs.h"
-#include "ui/scmessagebox.h"
+#include <chrono>
+#include <thread>
+
 #include <QObject>
 #include <QByteArray>
 #include <QMessageBox>
@@ -18,10 +16,11 @@
 #include <QStringList>
 #include <QTextCodec>
 
-#if defined(_WIN32) && !defined(usleep)
-#include <windows.h>
-#define usleep(t) Sleep((t > 1000) ? (t / 1000) : 1)
-#endif
+#include "docim.h"
+#include "gtwriter.h"
+#include "scpaths.h"
+#include "scribusstructs.h"
+#include "ui/scmessagebox.h"
 
 bool hasAntiword()
 {
@@ -39,7 +38,7 @@
 	{
 		found = true;
 		test->terminate();
-		usleep(5000);
+		std::this_thread::sleep_for(std::chrono::milliseconds(5));
 		test->kill();	
 	}
 	delete test;
@@ -69,7 +68,7 @@
 	DocIm *dim = new DocIm(filename, encoding, textOnly, writer);
 	while (dim->isRunning())
 	{
-		usleep(5000);
+		std::this_thread::sleep_for(std::chrono::milliseconds(5));
 	}
 	delete dim;
 }
@@ -113,7 +112,7 @@
 	}
 	while (proc->waitForReadyRead())
 	{
-		usleep(5000);
+		std::this_thread::sleep_for(std::chrono::milliseconds(5));
 	}
 
 	while(!proc->atEnd() || proc->state()==QProcess::Running)
@@ -136,7 +135,7 @@
 			}
 			else
 			{
-				usleep(5000);
+				std::this_thread::sleep_for(std::chrono::milliseconds(5));
 			}
 		}
 	}

Modified: trunk/Scribus/scribus/upgradechecker.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22698&path=/trunk/Scribus/scribus/upgradechecker.cpp
==============================================================================
--- trunk/Scribus/scribus/upgradechecker.cpp	(original)
+++ trunk/Scribus/scribus/upgradechecker.cpp	Wed Sep 19 18:11:08 2018
@@ -14,19 +14,15 @@
 #include <QTextStream>
 #include <QWidget>
 
+#include <chrono>
+#include <cstdlib>
 #include <iostream>
-#include <cstdlib>
+#include <thread>
 
 #include "prefsmanager.h"
 #include "scpaths.h"
 #include "scribuscore.h"
 #include "upgradechecker.h"
-
-
-#ifdef _WIN32
-#include <windows.h>
-#define sleep(t) Sleep(t*1000)
-#endif
 
 UpgradeChecker::UpgradeChecker()
 {
@@ -97,19 +93,17 @@
 			int waitCount=0;
 			while (!m_fin && waitCount<20)
 			{
-					sleep(1);
-					++waitCount;
-					if (m_writeToConsole)
-							std::cout << ". " << std::flush;
-					outputText( ".", true );
-					qApp->processEvents();
+				std::this_thread::sleep_for(std::chrono::seconds(1));
+				++waitCount;
+				if (m_writeToConsole)
+					std::cout << ". " << std::flush;
+				outputText( ".", true );
+				qApp->processEvents();
 			}
 			if (m_writeToConsole)
-					std::cout << std::endl;
-			if (waitCount>=20)
-			{
-					outputText("<b>"+ tr("Timed out when attempting to get update file.")+"</b>");
-			}
+				std::cout << std::endl;
+			if (waitCount >= 20)
+				outputText("<b>"+ tr("Timed out when attempting to get update file.")+"</b>");
 			m_file->close();
 		}
 		m_file->remove();




More information about the scribus-commit mailing list