Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#33 gettimeofday

open
nobody
None
5
2012-11-20
2004-05-19
Norbert Koch
No

In class SysTime you lock a mutex just
to call gettimeofday. This should - at
least for unix - not be required.
Here is my suggested patch:

--- thread.old Wed May 19 16:44:23 2004
+++ thread.cpp Wed May 19 16:50:00 2004
@@ -1632,25 +1632,20 @@

int SysTime::getTimeOfDay(struct timeval *tp)
{
- struct timeval temp;
- int ret(0);
- lock();
-
#ifdef WIN32
// We could use _ftime(), but it is not available on
WinCE.
// (WinCE also lacks time.h)
// Note also that the average error of _ftime is
around 20 ms :)
+ struct timeval temp;
+ lock();
time(&temp.tv_sec);
temp.tv_usec = (GetTickCount() % 1000) * 1000;
memcpy(tp, &temp, sizeof(struct timeval));
+ unlock();
#else
- ret = ::gettimeofday(&temp, NULL);
- if (ret == 0)
- memcpy(tp, &temp, sizeof(struct timeval));
+ ::gettimeofday(tp, NULL);
#endif
-
- unlock();
- return ret;
+ return 0;
}

struct tm *SysTime::getLocalTime(const time_t *clock,
struct tm* result)

Discussion