Skip to content

Commit

Permalink
replace VS implementation of gettimeofday with std::chrono::steady_cl…
Browse files Browse the repository at this point in the history
…ock::now(); fixes #2038
  • Loading branch information
zdenop committed Nov 8, 2018
1 parent f4a34e6 commit 2dd753e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 99 deletions.
7 changes: 0 additions & 7 deletions CMakeLists.txt
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cmake/SourceGroups.cmake
Expand Up @@ -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}")
5 changes: 0 additions & 5 deletions cppan.yml
Expand Up @@ -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
Expand All @@ -81,7 +79,6 @@ projects:
- src/lstm
- src/opencl
- src/textord
- src/vs2010/port
- src/viewer
- src/wordrec
#public:
Expand Down Expand Up @@ -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:
Expand Down
36 changes: 13 additions & 23 deletions src/ccutil/ocrclass.h
Expand Up @@ -26,15 +26,8 @@

#ifndef CCUTIL_OCRCLASS_H_
#define CCUTIL_OCRCLASS_H_

#ifndef __GNUC__
#ifdef _WIN32
#include "gettimeofday.h"
#endif
#else
#include <sys/time.h>
#endif
#include <ctime>
#include <chrono>
#include "host.h"

/*Maximum lengths of various strings*/
Expand Down Expand Up @@ -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

Expand All @@ -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<std::chrono::steady_clock,
std::chrono::milliseconds>();
}

// 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:
Expand Down
32 changes: 0 additions & 32 deletions src/vs2010/port/gettimeofday.cpp

This file was deleted.

31 changes: 0 additions & 31 deletions src/vs2010/port/gettimeofday.h

This file was deleted.

0 comments on commit 2dd753e

Please sign in to comment.