cleanup
This was SVN commit r390.
This commit is contained in:
parent
520e2a1ff6
commit
8e6e179187
@ -1,6 +1,6 @@
|
||||
// misc. POSIX routines for Win32
|
||||
//
|
||||
// Copyright (c) 2003 Jan Wassenberg
|
||||
// Copyright (c) 2004 Jan Wassenberg
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
@ -419,140 +419,6 @@ int munmap(void* start, size_t /* len */)
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// time
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
static const long _1e6 = 1000000;
|
||||
static const i64 _1e9 = 1000000000;
|
||||
|
||||
|
||||
// return nanoseconds since posix epoch
|
||||
// currently only 10 or 15 ms resolution! use HRT for finer timing
|
||||
static i64 st_time_ns()
|
||||
{
|
||||
union
|
||||
{
|
||||
FILETIME ft;
|
||||
i64 i;
|
||||
}
|
||||
t;
|
||||
GetSystemTimeAsFileTime(&t.ft);
|
||||
// Windows system time is hectonanoseconds since Jan. 1, 1601
|
||||
return (t.i - 0x019DB1DED53E8000) * 100;
|
||||
}
|
||||
|
||||
|
||||
static inline long st_res_ns()
|
||||
{
|
||||
DWORD adjust, interval;
|
||||
BOOL adj_disabled;
|
||||
GetSystemTimeAdjustment(&adjust, &interval, &adj_disabled);
|
||||
return interval * 100; // hns -> ns
|
||||
}
|
||||
|
||||
|
||||
static void sleep_ns(i64 ns)
|
||||
{
|
||||
DWORD ms = DWORD(ns / _1e6);
|
||||
if(ms != 0)
|
||||
Sleep(ms);
|
||||
else
|
||||
{
|
||||
i64 t0 = hrt_ticks(), t1;
|
||||
do
|
||||
t1 = hrt_ticks();
|
||||
while(hrt_delta_s(t0, t1) * _1e9 < ns);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int clock_gettime(clockid_t clock, struct timespec* t)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(clock != CLOCK_REALTIME || !t)
|
||||
{
|
||||
debug_warn("clock_gettime: invalid clock or t param");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
const i64 ns = st_time_ns();
|
||||
t->tv_sec = (time_t)(ns / _1e9);
|
||||
t->tv_nsec = (long) (ns % _1e9);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int clock_getres(clockid_t clock, struct timespec* res)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(clock != CLOCK_REALTIME || !res)
|
||||
{
|
||||
debug_warn("clock_getres: invalid clock or res param");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
res->tv_sec = 0;
|
||||
res->tv_nsec = st_res_ns();;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int nanosleep(const struct timespec* rqtp, struct timespec* /* rmtp */)
|
||||
{
|
||||
i64 ns = rqtp->tv_sec; // make sure we don't overflow
|
||||
ns *= _1e9;
|
||||
ns += rqtp->tv_nsec;
|
||||
sleep_ns(ns);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int gettimeofday(struct timeval* tv, void* tzp)
|
||||
{
|
||||
UNUSED(tzp);
|
||||
|
||||
#ifndef NDEBUG
|
||||
if(!tv)
|
||||
{
|
||||
debug_warn("gettimeofday: invalid t param");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
const i64 us = st_time_ns() / 1000;
|
||||
tv->tv_sec = (time_t) (us / _1e6);
|
||||
tv->tv_usec = (suseconds_t)(us % _1e6);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint sleep(uint sec)
|
||||
{
|
||||
Sleep(sec * 1000);
|
||||
return sec;
|
||||
}
|
||||
|
||||
|
||||
int usleep(useconds_t us)
|
||||
{
|
||||
// can't overflow, because us < 1e6
|
||||
sleep_ns(us * 1000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int uname(struct utsname* un)
|
||||
|
@ -77,8 +77,6 @@ typedef unsigned long long uint64_t;
|
||||
// <sys/types.h>
|
||||
//
|
||||
|
||||
typedef unsigned long useconds_t;
|
||||
typedef long suseconds_t;
|
||||
typedef long ssize_t;
|
||||
|
||||
|
||||
@ -86,7 +84,8 @@ typedef long ssize_t;
|
||||
// <limits.h>
|
||||
//
|
||||
|
||||
#define PATH_MAX 260
|
||||
#define PATH_MAX 256
|
||||
// Win32 MAX_PATH is 260
|
||||
|
||||
|
||||
//
|
||||
@ -236,10 +235,6 @@ extern int access(const char*, int);
|
||||
extern int chdir(const char*);
|
||||
#define getcwd _getcwd
|
||||
|
||||
|
||||
extern unsigned int sleep(unsigned int sec);
|
||||
extern int usleep(useconds_t us);
|
||||
|
||||
// user tests if available via #ifdef; can't use enum.
|
||||
#define _SC_PAGESIZE 1
|
||||
#define _SC_PAGE_SIZE 1
|
||||
@ -339,36 +334,6 @@ extern int pthread_mutex_unlock(pthread_mutex_t*);
|
||||
extern int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*);
|
||||
|
||||
|
||||
//
|
||||
// <time.h>
|
||||
//
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CLOCK_REALTIME
|
||||
}
|
||||
clockid_t;
|
||||
|
||||
// BSD gettimeofday
|
||||
struct timeval
|
||||
{
|
||||
time_t tv_sec;
|
||||
suseconds_t tv_usec;
|
||||
};
|
||||
|
||||
// POSIX realtime clock_*
|
||||
struct timespec
|
||||
{
|
||||
time_t tv_sec;
|
||||
long tv_nsec;
|
||||
};
|
||||
|
||||
extern int gettimeofday(struct timeval* tv, void* tzp);
|
||||
|
||||
extern int nanosleep(const struct timespec* rqtp, struct timespec* rmtp);
|
||||
extern int clock_gettime(clockid_t clock, struct timespec* ts);
|
||||
extern int clock_getres(clockid_t clock, struct timespec* res);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -437,6 +402,7 @@ extern void _hide_console();
|
||||
// split out of this module
|
||||
#include "waio.h"
|
||||
#include "wsock.h"
|
||||
#include "wtime.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,3 +1,20 @@
|
||||
// Berkeley sockets emulation for Win32
|
||||
// Copyright (c) 2004 Jan Wassenberg
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// Contact info:
|
||||
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
||||
// http://www.stud.uni-karlsruhe.de/~urkt/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "win_internal.h"
|
||||
|
@ -1,3 +1,20 @@
|
||||
// Berkeley sockets emulation for Win32
|
||||
// Copyright (c) 2004 Jan Wassenberg
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// Contact info:
|
||||
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
||||
// http://www.stud.uni-karlsruhe.de/~urkt/
|
||||
|
||||
#ifndef WSOCK_H__
|
||||
#define WSOCK_H__
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user