Re: Highres delay help

From: A. Melinte (nospam_at_nospam.com)
Date: 05/27/05


Date: Fri, 27 May 2005 14:01:18 -0400


"Carl W" <calle79@inorbit.com> wrote in message
news:c6416781.0505270421.5ff3ef02@posting.google.com...
> Dear all.
>
> I need a way to implement a high resolution delay with at least a
> resolution of 1 ms.

You can use select() to have a microsec resolution in a portable way:

/* restart select if call interrupted */
static int
rselect( int n, fd_set *rds, fd_set *wds, fd_set *eds, struct timeval
*tout )
{
    int rc;

    do {
        rc = select( n, rds, wds, eds, tout );
    } while ( rc == -1 && errno == EINTR );

    return rc;
}

int
microsleep( int sock, int microsec )
{
    struct timeval tv;
    fd_set rfs, wfs, efs;
    int ret;

    tv.tv_sec = 0;
    tv.tv_usec = microsec;

    if ( sock == CFGST_INVALID_SOCKET ) {
        ret = rselect( 0, NULL, NULL, NULL, &tv );
    } else {
        FD_ZERO( &rfs ); FD_SET( sock, &rfs );
        FD_ZERO( &wfs ); //FD_SET( sock, &wfs );
        FD_ZERO( &efs ); //FD_SET( sock, &efs );
        ret = rselect( sock+1, &rfs, &wfs, &efs, &tv );
    }

    return ret;
}



Relevant Pages

  • Re: Linux 2.6.23.17
    ... goto fail; ... * the resolution of the device's medium. ... +static void default_shutdown(unsigned int irq) ... We kill this session and block the SYN/ACK so ...
    (Linux-Kernel)
  • get the time needed to process one function.
    ... int a; ... The C standard doesn't specify a particular resolution, ... You can use a profiling tool if you have one available. ... You can tell us what platform you're on, ...
    (comp.lang.c)
  • Re: Operator overloading in C
    ... I think that's spelled "...when int and long ... Synonyms will be promoted within name resolution to each other ... to avoid repeating code. ...
    (comp.std.c)
  • Re: 2GB limit on samba and nfs?
    ... >>Did you ever get a resolution for this? ... the 32-bit file pointer issue. ... Linux, this limits programs to a 2GB file size, because it's a signed ... On Windows, I think they treat it as an unsigned int ...
    (Fedora)
  • Re: Error - Declaring static arrays of structs in a class (VC6)
    ... bore bits (32 bits for an int, more than 32 bits for an std::string)... ... > resolution was ambiguous ... This code works fine if we replace string objects in S struct with ...
    (microsoft.public.vc.language)