This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 390 for ps


Ignore:
Timestamp:
06/03/04 20:36:48 (21 years ago)
Author:
janwas
Message:

cleanup

Location:
ps/trunk/source/lib/sysdep/win
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/lib/sysdep/win/wposix.cpp

    r378 r390  
    11// misc. POSIX routines for Win32
    22//
    3 // Copyright (c) 2003 Jan Wassenberg
     3// Copyright (c) 2004 Jan Wassenberg
    44//
    55// This program is free software; you can redistribute it and/or
     
    420420
    421421
    422 //////////////////////////////////////////////////////////////////////////////
    423 //
    424 // time
    425 //
    426 //////////////////////////////////////////////////////////////////////////////
    427 
    428 
    429 static const long _1e6 = 1000000;
    430 static const i64 _1e9 = 1000000000;
    431 
    432 
    433 // return nanoseconds since posix epoch
    434 // currently only 10 or 15 ms resolution! use HRT for finer timing
    435 static i64 st_time_ns()
    436 {
    437     union
    438     {
    439         FILETIME ft;
    440         i64 i;
    441     }
    442     t;
    443     GetSystemTimeAsFileTime(&t.ft);
    444     // Windows system time is hectonanoseconds since Jan. 1, 1601
    445     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 -> ns
    455 }
    456 
    457 
    458 static void sleep_ns(i64 ns)
    459 {
    460     DWORD ms = DWORD(ns / _1e6);
    461     if(ms != 0)
    462         Sleep(ms);
    463     else
    464     {
    465         i64 t0 = hrt_ticks(), t1;
    466         do
    467             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 NDEBUG
    476     if(clock != CLOCK_REALTIME || !t)
    477     {
    478         debug_warn("clock_gettime: invalid clock or t param");
    479         return -1;
    480     }
    481 #endif
    482 
    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 NDEBUG
    493     if(clock != CLOCK_REALTIME || !res)
    494     {
    495         debug_warn("clock_getres: invalid clock or res param");
    496         return -1;
    497     }
    498 #endif
    499 
    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 overflow
    509     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 NDEBUG
    522     if(!tv)
    523     {
    524         debug_warn("gettimeofday: invalid t param");
    525         return -1;
    526     }
    527 #endif
    528 
    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 < 1e6
    546     sleep_ns(us * 1000);
    547     return 0;
    548 }
    549 
    550 
    551 
    552 
    553 
    554 
    555 
    556422
    557423
  • ps/trunk/source/lib/sysdep/win/wposix.h

    r378 r390  
    7878//
    7979
    80 typedef unsigned long useconds_t;
    81 typedef long suseconds_t;
    8280typedef long ssize_t;
    8381
     
    8785//
    8886
    89 #define PATH_MAX 260
     87#define PATH_MAX 256
     88// Win32 MAX_PATH is 260
    9089
    9190
     
    237236#define getcwd _getcwd
    238237
    239 
    240 extern unsigned int sleep(unsigned int sec);
    241 extern int usleep(useconds_t us);
    242 
    243238// user tests if available via #ifdef; can't use enum.
    244239#define _SC_PAGESIZE      1
     
    339334extern int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*);
    340335
    341 
    342 //
    343 // <time.h>
    344 //
    345 
    346 typedef enum
    347 {
    348     CLOCK_REALTIME
    349 }
    350 clockid_t;
    351 
    352 // BSD gettimeofday
    353 struct timeval
    354 {
    355     time_t tv_sec;
    356     suseconds_t tv_usec;
    357 };
    358 
    359 // POSIX realtime clock_*
    360 struct timespec
    361 {
    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);
    371336
    372337
     
    438403#include "waio.h"
    439404#include "wsock.h"
     405#include "wtime.h"
    440406
    441407
  • 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
    118#include "precompiled.h"
    219
  • 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
    118#ifndef WSOCK_H__
    219#define WSOCK_H__
Note: See TracChangeset for help on using the changeset viewer.