From 2dd753ee4c8fc450e289437a9a19a206fbf4659f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdenko=20Podobn=C3=BD?= Date: Thu, 8 Nov 2018 16:42:32 +0100 Subject: [PATCH] replace VS implementation of gettimeofday with std::chrono::steady_clock::now(); fixes #2038 --- CMakeLists.txt | 7 ------- cmake/SourceGroups.cmake | 1 - cppan.yml | 5 ----- src/ccutil/ocrclass.h | 36 ++++++++++++-------------------- src/vs2010/port/gettimeofday.cpp | 32 ---------------------------- src/vs2010/port/gettimeofday.h | 31 --------------------------- 6 files changed, 13 insertions(+), 99 deletions(-) delete mode 100644 src/vs2010/port/gettimeofday.cpp delete mode 100644 src/vs2010/port/gettimeofday.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c05661b62..5cdd24b7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,7 +173,6 @@ include_directories(src/dict) include_directories(src/lstm) include_directories(src/opencl) include_directories(src/textord) -include_directories(src/vs2010/port) include_directories(src/viewer) include_directories(src/wordrec) @@ -210,12 +209,6 @@ file(GLOB tesseract_hdr src/viewer/*.h src/wordrec/*.h ) -if (WIN32) - file(GLOB tesseract_win32_src "src/vs2010/port/*.cpp") - file(GLOB tesseract_win32_hdr "src/vs2010/port/*.h") - set(tesseract_src ${tesseract_src} ${tesseract_win32_src}) - set(tesseract_hdr ${tesseract_hdr} ${tesseract_win32_hdr}) -endif() set(tesseract_src ${tesseract_src} src/api/baseapi.cpp diff --git a/cmake/SourceGroups.cmake b/cmake/SourceGroups.cmake index 4bc6e3fab..b21763c3b 100644 --- a/cmake/SourceGroups.cmake +++ b/cmake/SourceGroups.cmake @@ -34,5 +34,4 @@ source_group("lstm" "${SSRC}/lstm/${H_CPP}") source_group("opencl" "${SSRC}/opencl/${H_CPP}") source_group("textord" "${SSRC}/textord/${H_CPP}") source_group("viewer" "${SSRC}/viewer/${H_CPP}") -source_group("port" "${SSRC}/vs2010/port/${H_CPP}") source_group("wordrec" "${SSRC}/wordrec/${H_CPP}") diff --git a/cppan.yml b/cppan.yml index 37a9a42d9..ec3e712df 100644 --- a/cppan.yml +++ b/cppan.yml @@ -64,8 +64,6 @@ projects: - src/viewer/.*\.h - src/wordrec/.*\.h - - src/vs2010/port/.* - exclude_from_build: - src/api/tesseractmain.cpp - src/viewer/svpaint.cpp @@ -81,7 +79,6 @@ projects: - src/lstm - src/opencl - src/textord - - src/vs2010/port - src/viewer - src/wordrec #public: @@ -140,8 +137,6 @@ projects: ${SDIR}/src/arch/intsimdmatrixavx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2") endif() - else() - remove_src_dir(src/vs2010/port/*) endif() options: diff --git a/src/ccutil/ocrclass.h b/src/ccutil/ocrclass.h index 77272c4b7..8d1a9cb89 100644 --- a/src/ccutil/ocrclass.h +++ b/src/ccutil/ocrclass.h @@ -26,15 +26,8 @@ #ifndef CCUTIL_OCRCLASS_H_ #define CCUTIL_OCRCLASS_H_ - -#ifndef __GNUC__ -#ifdef _WIN32 -#include "gettimeofday.h" -#endif -#else -#include -#endif #include +#include #include "host.h" /*Maximum lengths of various strings*/ @@ -130,7 +123,8 @@ class ETEXT_DESC { // output header PROGRESS_FUNC progress_callback; /// called whenever progress increases PROGRESS_FUNC2 progress_callback2;/// monitor-aware progress callback void* cancel_this; /// this or other data for cancel - struct timeval end_time; /// Time to stop. Expected to be set only + std::chrono::steady_clock::time_point end_time; + /// Time to stop. Expected to be set only /// by call to set_deadline_msecs(). EANYCODE_CHAR text[1]; /// character data @@ -144,29 +138,25 @@ class ETEXT_DESC { // output header progress_callback(nullptr), progress_callback2(&default_progress_func), cancel_this(nullptr) { - end_time.tv_sec = 0; - end_time.tv_usec = 0; + end_time = std::chrono::time_point(); } // Sets the end time to be deadline_msecs milliseconds from now. void set_deadline_msecs(int32_t deadline_msecs) { - gettimeofday(&end_time, nullptr); - int32_t deadline_secs = deadline_msecs / 1000; - end_time.tv_sec += deadline_secs; - end_time.tv_usec += (deadline_msecs - deadline_secs * 1000) * 1000; - if (end_time.tv_usec > 1000000) { - end_time.tv_usec -= 1000000; - ++end_time.tv_sec; + if (deadline_msecs > 0) { + end_time = std::chrono::steady_clock::now() + + std::chrono::milliseconds(deadline_msecs); } } // Returns false if we've not passed the end_time, or have not set a deadline. bool deadline_exceeded() const { - if (end_time.tv_sec == 0 && end_time.tv_usec == 0) return false; - struct timeval now; - gettimeofday(&now, nullptr); - return (now.tv_sec > end_time.tv_sec || (now.tv_sec == end_time.tv_sec && - now.tv_usec > end_time.tv_usec)); + if (end_time.time_since_epoch() == + std::chrono::steady_clock::duration::zero()) + return false; + auto now = std::chrono::steady_clock::now(); + return (now > end_time); } private: diff --git a/src/vs2010/port/gettimeofday.cpp b/src/vs2010/port/gettimeofday.cpp deleted file mode 100644 index 664ea7304..000000000 --- a/src/vs2010/port/gettimeofday.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// File: gettimeofday.cpp -// Description: Implementation of gettimeofday based on leptonica -// Author: tomp2010, zdenop -// Created: Tue Feb 21 21:38:00 CET 2012 -// -// (C) Copyright 2012, Google Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -/////////////////////////////////////////////////////////////////////// - -#include -#include "gettimeofday.h" - -int gettimeofday(struct timeval *tp, struct timezone *tzp) { - l_int32 sec, usec; - if (tp == nullptr) - return -1; - - l_getCurrentTime(&sec, &usec); - tp->tv_sec = sec; - tp->tv_usec = usec; - return 0; -} diff --git a/src/vs2010/port/gettimeofday.h b/src/vs2010/port/gettimeofday.h deleted file mode 100644 index 621ecd3b9..000000000 --- a/src/vs2010/port/gettimeofday.h +++ /dev/null @@ -1,31 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// File: gettimeofday.h -// Description: Header file for gettimeofday.cpp -// Author: tomp2010, zdenop -// Created: Tue Feb 21 21:38:00 CET 2012 -// -// (C) Copyright 2012, Google Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -/////////////////////////////////////////////////////////////////////// - -#ifndef VS2008_PORT_GETTIMEOFDAY_H_ -#define VS2008_PORT_GETTIMEOFDAY_H_ - -#ifdef _WIN32 -#include // timeval is defined in here. -#endif - -typedef struct timezone tz; - -int gettimeofday(struct timeval * tp, struct timezone * tzp); - -#endif // VS2008_PORT_GETTIMEOFDAY_H_