Browse Source

Move from the thread safe localtime_r to regular localtime which is the only one supported on newer pthread libraries on mingw32 to make it compile with

the newer ming. Thread safety is of no importance where localtime is used in this code.
nfactor-troky
Con Kolivas 13 years ago
parent
commit
5b4761003c
  1. 40
      cgminer.c
  2. 16
      util.c

40
cgminer.c

@ -238,16 +238,16 @@ static bool time_before(struct tm *tm1, struct tm *tm2) @@ -238,16 +238,16 @@ static bool time_before(struct tm *tm1, struct tm *tm2)
static bool should_run(void)
{
struct timeval tv;
struct tm tm;
struct tm *tm;
if (!schedstart.enable && !schedstop.enable)
return true;
gettimeofday(&tv, NULL);
localtime_r(&tv.tv_sec, &tm);
tm = localtime(&tv.tv_sec);
if (schedstart.enable) {
if (!schedstop.enable) {
if (time_before(&tm, &schedstart.tm))
if (time_before(tm, &schedstart.tm))
return false;
/* This is a once off event with no stop time set */
@ -255,46 +255,46 @@ static bool should_run(void) @@ -255,46 +255,46 @@ static bool should_run(void)
return true;
}
if (time_before(&schedstart.tm, &schedstop.tm)) {
if (time_before(&tm, &schedstop.tm) && !time_before(&tm, &schedstart.tm))
if (time_before(tm, &schedstop.tm) && !time_before(tm, &schedstart.tm))
return true;
return false;
} /* Times are reversed */
if (time_before(&tm, &schedstart.tm)) {
if (time_before(&tm, &schedstop.tm))
if (time_before(tm, &schedstart.tm)) {
if (time_before(tm, &schedstop.tm))
return true;
return false;
}
return true;
}
/* only schedstop.enable == true */
if (!time_before(&tm, &schedstop.tm))
if (!time_before(tm, &schedstop.tm))
return false;
return true;
}
void get_datestamp(char *f, struct timeval *tv)
{
struct tm tm;
struct tm *tm;
localtime_r(&tv->tv_sec, &tm);
tm = localtime(&tv->tv_sec);
sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
}
void get_timestamp(char *f, struct timeval *tv)
{
struct tm tm;
struct tm *tm;
localtime_r(&tv->tv_sec, &tm);
tm = localtime(&tv->tv_sec);
sprintf(f, "[%02d:%02d:%02d]",
tm.tm_hour,
tm.tm_min,
tm.tm_sec);
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
}
static void applog_and_exit(const char *fmt, ...)

16
util.c

@ -79,21 +79,21 @@ void vapplog(int prio, const char *fmt, va_list ap) @@ -79,21 +79,21 @@ void vapplog(int prio, const char *fmt, va_list ap)
char *f;
int len;
struct timeval tv = { };
struct tm tm;
struct tm *tm;
gettimeofday(&tv, NULL);
localtime_r(&tv.tv_sec, &tm);
tm = localtime(&tv.tv_sec);
len = 40 + strlen(fmt) + 22;
f = alloca(len);
sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s\n",
tm.tm_year + 1900,
tm.tm_mon + 1,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec,
fmt);
/* Only output to stderr if it's not going to the screen as well */
if (!isatty(fileno((FILE *)stderr))) {

Loading…
Cancel
Save