Skip to content

include gettimeofday.h to installed headers #2038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zdenop opened this issue Oct 30, 2018 · 7 comments
Closed

include gettimeofday.h to installed headers #2038

zdenop opened this issue Oct 30, 2018 · 7 comments

Comments

@zdenop
Copy link
Contributor

zdenop commented Oct 30, 2018

gettimeofday.h in not part of installed headers (neither via cmake or autotools), but it is included in installed header ocrclass.h.

So using ocrclass.h on windows will cause error about missing header file.

@zdenop zdenop changed the title include gettimeofday.h to installed header include gettimeofday.h to installed headers Oct 30, 2018
@stweil
Copy link
Member

stweil commented Oct 30, 2018

gettimeofday is only called from ocrclass.h. I'd prefer to eliminate the complete directory src/vs2010/port.

@stweil
Copy link
Member

stweil commented Oct 30, 2018

Can ocrclass.h be removed from the public API? baseapi.h also compiles without it as soon as the include statement is removed.

@amitdo
Copy link
Collaborator

amitdo commented Oct 30, 2018

int TessBaseAPI::Recognize(ETEXT_DESC* monitor) {

@zdenop
Copy link
Contributor Author

zdenop commented Oct 30, 2018

No, ocrclass.h can not be removed from public API, because it defines ETEXT_DESC and it would eliminated possibility to use monitor.

src/vs2010/port can be eliminated if gettimeofday is replaced with something platform independed...

@zdenop
Copy link
Contributor Author

zdenop commented Nov 2, 2018

I did not test it deeply, but is seems this could get rid of gettimeofday:

diff --git a/src/ccutil/ocrclass.h b/src/ccutil/ocrclass.h
index 77272c4b..8d1a9cb8 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          <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:

@zdenop
Copy link
Contributor Author

zdenop commented Nov 4, 2018

quick observation: tessedit.h only declares ETEXT_DESC monitor... maybe it could eliminated...

@stweil
Copy link
Member

stweil commented Nov 8, 2018

Pull request #2045 addresses this issue by eliminating gettimeofday.h.

@zdenop zdenop closed this as completed in 2dd753e Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants