mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-06 01:04:57 +08:00
replace VS implementation of gettimeofday with std::chrono::steady_clock::now(); fixes #2038
This commit is contained in:
parent
f4a34e6ddf
commit
2dd753ee4c
@ -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
|
||||
|
@ -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}")
|
||||
|
@ -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:
|
||||
|
@ -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*/
|
||||
@ -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<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:
|
||||
|
@ -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 <allheaders.h>
|
||||
#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;
|
||||
}
|
@ -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 <winsock.h> // timeval is defined in here.
|
||||
#endif
|
||||
|
||||
typedef struct timezone tz;
|
||||
|
||||
int gettimeofday(struct timeval * tp, struct timezone * tzp);
|
||||
|
||||
#endif // VS2008_PORT_GETTIMEOFDAY_H_
|
Loading…
Reference in New Issue
Block a user