avoid redefining sched_yield (Christian Pfeil)
This commit is contained in:
parent
c772232802
commit
5db07ba942
2 changed files with 38 additions and 63 deletions
|
|
@ -1,30 +1,28 @@
|
||||||
#include <u.h>
|
|
||||||
#include <stdlib.h> /* setenv etc. */
|
|
||||||
#define NOPLAN9DEFINES
|
#define NOPLAN9DEFINES
|
||||||
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
#include <stdlib.h> /* setenv etc. */
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define _HAVETIMEGM 1
|
static int didtz;
|
||||||
#define _HAVETMZONE 1
|
static int tzdelta;
|
||||||
#define _HAVETMGMTOFF 1
|
static char tzone[4];
|
||||||
|
|
||||||
#if defined(__linux__)
|
|
||||||
# undef _HAVETMZONE
|
|
||||||
|
|
||||||
#elif defined(__sun__)
|
|
||||||
# undef _HAVETIMEGM
|
|
||||||
# undef _HAVETMZONE
|
|
||||||
# undef _HAVETMGMTOFF
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static Tm bigtm;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tm2Tm(struct tm *tm, Tm *bigtm)
|
dotz(void)
|
||||||
{
|
{
|
||||||
char *s;
|
time_t t;
|
||||||
|
|
||||||
|
if(didtz)
|
||||||
|
return;
|
||||||
|
t = time(0);
|
||||||
|
tzdelta = t - mktime(gmtime(&t));
|
||||||
|
strftime(tzone, sizeof tzone, "%Z", localtime(&t));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
tm2Tm(struct tm *tm, Tm *bigtm, int gmt)
|
||||||
|
{
|
||||||
memset(bigtm, 0, sizeof *bigtm);
|
memset(bigtm, 0, sizeof *bigtm);
|
||||||
bigtm->sec = tm->tm_sec;
|
bigtm->sec = tm->tm_sec;
|
||||||
bigtm->min = tm->tm_min;
|
bigtm->min = tm->tm_min;
|
||||||
|
|
@ -33,17 +31,13 @@ tm2Tm(struct tm *tm, Tm *bigtm)
|
||||||
bigtm->mon = tm->tm_mon;
|
bigtm->mon = tm->tm_mon;
|
||||||
bigtm->year = tm->tm_year;
|
bigtm->year = tm->tm_year;
|
||||||
bigtm->wday = tm->tm_wday;
|
bigtm->wday = tm->tm_wday;
|
||||||
strftime(bigtm->zone, sizeof bigtm->zone, "%Z", tm);
|
if(gmt){
|
||||||
#ifdef _HAVETMGMTOFF
|
strcpy(bigtm->zone, "GMT");
|
||||||
bigtm->tzoff = tm->tm_gmtoff;
|
bigtm->tzoff = 0;
|
||||||
#endif
|
}else{
|
||||||
|
dotz();
|
||||||
if(bigtm->zone[0] == 0){
|
strcpy(bigtm->zone, tzone);
|
||||||
s = getenv("TIMEZONE");
|
bigtm->tzoff = tzdelta;
|
||||||
if(s){
|
|
||||||
strecpy(bigtm->zone, bigtm->zone+4, s);
|
|
||||||
free(s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,12 +52,6 @@ Tm2tm(Tm *bigtm, struct tm *tm)
|
||||||
tm->tm_mon = bigtm->mon;
|
tm->tm_mon = bigtm->mon;
|
||||||
tm->tm_year = bigtm->year;
|
tm->tm_year = bigtm->year;
|
||||||
tm->tm_wday = bigtm->wday;
|
tm->tm_wday = bigtm->wday;
|
||||||
#ifdef _HAVETMZONE
|
|
||||||
tm->tm_zone = bigtm->zone;
|
|
||||||
#endif
|
|
||||||
#ifdef _HAVETMGMTOFF
|
|
||||||
tm->tm_gmtoff = bigtm->tzoff;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Tm*
|
Tm*
|
||||||
|
|
@ -71,10 +59,11 @@ p9gmtime(long x)
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
static Tm bigtm;
|
||||||
|
|
||||||
t = (time_t)x;
|
t = (time_t)x;
|
||||||
tm = *gmtime(&t);
|
tm = *gmtime(&t);
|
||||||
tm2Tm(&tm, &bigtm);
|
tm2Tm(&tm, &bigtm, 1);
|
||||||
return &bigtm;
|
return &bigtm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,42 +72,26 @@ p9localtime(long x)
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
static Tm bigtm;
|
||||||
|
|
||||||
t = (time_t)x;
|
t = (time_t)x;
|
||||||
tm = *localtime(&t);
|
tm = *localtime(&t);
|
||||||
tm2Tm(&tm, &bigtm);
|
tm2Tm(&tm, &bigtm, 0);
|
||||||
return &bigtm;
|
return &bigtm;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(_HAVETIMEGM)
|
|
||||||
static time_t
|
|
||||||
timegm(struct tm *tm)
|
|
||||||
{
|
|
||||||
time_t ret;
|
|
||||||
char *tz;
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
tz = getenv("TZ");
|
|
||||||
putenv("TZ=");
|
|
||||||
tzset();
|
|
||||||
ret = mktime(tm);
|
|
||||||
if(tz){
|
|
||||||
s = smprint("TZ=%s", tz);
|
|
||||||
if(s)
|
|
||||||
putenv(s);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
long
|
long
|
||||||
p9tm2sec(Tm *bigtm)
|
p9tm2sec(Tm *bigtm)
|
||||||
{
|
{
|
||||||
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
|
||||||
Tm2tm(bigtm, &tm);
|
Tm2tm(bigtm, &tm);
|
||||||
if(strcmp(bigtm->zone, "GMT") == 0 || strcmp(bigtm->zone, "UCT") == 0)
|
t = mktime(&tm);
|
||||||
return timegm(&tm);
|
if(strcmp(bigtm->zone, "GMT") == 0 || strcmp(bigtm->zone, "UCT") == 0){
|
||||||
return mktime(&tm); /* local time zone */
|
dotz();
|
||||||
|
t += tzdelta;
|
||||||
|
}
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
|
||||||
#if defined(__NetBSD__) || (defined(__OpenBSD__) && OpenBSD <= 200511)
|
#if defined(__NetBSD__) || (defined(__OpenBSD__) && OpenBSD <= 200511)
|
||||||
|
#if !defined(sched_yield)
|
||||||
# define sched_yield() \
|
# define sched_yield() \
|
||||||
do{ struct timespec ts; \
|
do{ struct timespec ts; \
|
||||||
ts.tv_sec = 0; \
|
ts.tv_sec = 0; \
|
||||||
|
|
@ -13,6 +14,7 @@
|
||||||
nanosleep(&ts, 0); \
|
nanosleep(&ts, 0); \
|
||||||
}while(0)
|
}while(0)
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
p9sleep(long milli)
|
p9sleep(long milli)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue