- Timestamp:
- 06/03/04 20:36:48 (21 years ago)
- Location:
- ps/trunk/source/lib/sysdep/win
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/lib/sysdep/win/wposix.cpp
r378 r390 1 1 // misc. POSIX routines for Win32 2 2 // 3 // Copyright (c) 200 3Jan Wassenberg3 // Copyright (c) 2004 Jan Wassenberg 4 4 // 5 5 // This program is free software; you can redistribute it and/or … … 420 420 421 421 422 //////////////////////////////////////////////////////////////////////////////423 //424 // time425 //426 //////////////////////////////////////////////////////////////////////////////427 428 429 static const long _1e6 = 1000000;430 static const i64 _1e9 = 1000000000;431 432 433 // return nanoseconds since posix epoch434 // currently only 10 or 15 ms resolution! use HRT for finer timing435 static i64 st_time_ns()436 {437 union438 {439 FILETIME ft;440 i64 i;441 }442 t;443 GetSystemTimeAsFileTime(&t.ft);444 // Windows system time is hectonanoseconds since Jan. 1, 1601445 return (t.i - 0x019DB1DED53E8000) * 100;446 }447 448 449 static inline long st_res_ns()450 {451 DWORD adjust, interval;452 BOOL adj_disabled;453 GetSystemTimeAdjustment(&adjust, &interval, &adj_disabled);454 return interval * 100; // hns -> ns455 }456 457 458 static void sleep_ns(i64 ns)459 {460 DWORD ms = DWORD(ns / _1e6);461 if(ms != 0)462 Sleep(ms);463 else464 {465 i64 t0 = hrt_ticks(), t1;466 do467 t1 = hrt_ticks();468 while(hrt_delta_s(t0, t1) * _1e9 < ns);469 }470 }471 472 473 int clock_gettime(clockid_t clock, struct timespec* t)474 {475 #ifndef NDEBUG476 if(clock != CLOCK_REALTIME || !t)477 {478 debug_warn("clock_gettime: invalid clock or t param");479 return -1;480 }481 #endif482 483 const i64 ns = st_time_ns();484 t->tv_sec = (time_t)(ns / _1e9);485 t->tv_nsec = (long) (ns % _1e9);486 return 0;487 }488 489 490 int clock_getres(clockid_t clock, struct timespec* res)491 {492 #ifndef NDEBUG493 if(clock != CLOCK_REALTIME || !res)494 {495 debug_warn("clock_getres: invalid clock or res param");496 return -1;497 }498 #endif499 500 res->tv_sec = 0;501 res->tv_nsec = st_res_ns();;502 return 0;503 }504 505 506 int nanosleep(const struct timespec* rqtp, struct timespec* /* rmtp */)507 {508 i64 ns = rqtp->tv_sec; // make sure we don't overflow509 ns *= _1e9;510 ns += rqtp->tv_nsec;511 sleep_ns(ns);512 return 0;513 }514 515 516 517 int gettimeofday(struct timeval* tv, void* tzp)518 {519 UNUSED(tzp);520 521 #ifndef NDEBUG522 if(!tv)523 {524 debug_warn("gettimeofday: invalid t param");525 return -1;526 }527 #endif528 529 const i64 us = st_time_ns() / 1000;530 tv->tv_sec = (time_t) (us / _1e6);531 tv->tv_usec = (suseconds_t)(us % _1e6);532 return 0;533 }534 535 536 uint sleep(uint sec)537 {538 Sleep(sec * 1000);539 return sec;540 }541 542 543 int usleep(useconds_t us)544 {545 // can't overflow, because us < 1e6546 sleep_ns(us * 1000);547 return 0;548 }549 550 551 552 553 554 555 556 422 557 423 -
ps/trunk/source/lib/sysdep/win/wposix.h
r378 r390 78 78 // 79 79 80 typedef unsigned long useconds_t;81 typedef long suseconds_t;82 80 typedef long ssize_t; 83 81 … … 87 85 // 88 86 89 #define PATH_MAX 260 87 #define PATH_MAX 256 88 // Win32 MAX_PATH is 260 90 89 91 90 … … 237 236 #define getcwd _getcwd 238 237 239 240 extern unsigned int sleep(unsigned int sec);241 extern int usleep(useconds_t us);242 243 238 // user tests if available via #ifdef; can't use enum. 244 239 #define _SC_PAGESIZE 1 … … 339 334 extern int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*); 340 335 341 342 //343 // <time.h>344 //345 346 typedef enum347 {348 CLOCK_REALTIME349 }350 clockid_t;351 352 // BSD gettimeofday353 struct timeval354 {355 time_t tv_sec;356 suseconds_t tv_usec;357 };358 359 // POSIX realtime clock_*360 struct timespec361 {362 time_t tv_sec;363 long tv_nsec;364 };365 366 extern int gettimeofday(struct timeval* tv, void* tzp);367 368 extern int nanosleep(const struct timespec* rqtp, struct timespec* rmtp);369 extern int clock_gettime(clockid_t clock, struct timespec* ts);370 extern int clock_getres(clockid_t clock, struct timespec* res);371 336 372 337 … … 438 403 #include "waio.h" 439 404 #include "wsock.h" 405 #include "wtime.h" 440 406 441 407 -
ps/trunk/source/lib/sysdep/win/wsock.cpp
r334 r390 1 // Berkeley sockets emulation for Win32 2 // Copyright (c) 2004 Jan Wassenberg 3 // 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License as 6 // published by the Free Software Foundation; either version 2 of the 7 // License, or (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // General Public License for more details. 13 // 14 // Contact info: 15 // Jan.Wassenberg@stud.uni-karlsruhe.de 16 // http://www.stud.uni-karlsruhe.de/~urkt/ 17 1 18 #include "precompiled.h" 2 19 -
ps/trunk/source/lib/sysdep/win/wsock.h
r334 r390 1 // Berkeley sockets emulation for Win32 2 // Copyright (c) 2004 Jan Wassenberg 3 // 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License as 6 // published by the Free Software Foundation; either version 2 of the 7 // License, or (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // General Public License for more details. 13 // 14 // Contact info: 15 // Jan.Wassenberg@stud.uni-karlsruhe.de 16 // http://www.stud.uni-karlsruhe.de/~urkt/ 17 1 18 #ifndef WSOCK_H__ 2 19 #define WSOCK_H__
Note:
See TracChangeset
for help on using the changeset viewer.
