bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug on getTimeout()


From: David Sugar
Subject: Re: bug on getTimeout()
Date: Tue, 9 Dec 2003 13:23:41 -0500
User-agent: KMail/1.5.3

Strangly enough I am testing this particular code right now...in fact, I stand 
slightly corrected:

        gettimeofday(&current, NULL);
        spec->tv_sec = current.tv_sec + ((timer + current.tv_usec / 1000) / 
1000);
        spec->tv_nsec = ((current.tv_usec / 1000 + timer) % 1000) * 1000000;

tod is microseconds, not milli :)

On Tuesday 09 December 2003 03:08 am, address@hidden wrote:
> I'm using common cpp on dec alpha processor with unix system.
>
> Mi application go up to 100% of cpu usage and i found that event::wait does
> not work correctly.
>
>
>
> timespec *getTimeout(struct timespec *spec, timeout_t timer)
>
> {
>
>       static  struct timespec myspec;
>
>
>
>       if(spec == NULL)
>
>               spec = &myspec;
>
>
>
> #ifdef        PTHREAD_GET_EXPIRATION_NP
>
>       struct timespec offset;
>
>
>
>       offset.tv_sec = timer / 1000;
>
>       offset.tv_nsec = (timer % 1000) * 1000000;
>
>       pthread_get_expiration_np(&offset, sec);
>
> #else
>
>       struct timeval current;
>
>
>
>       gettimeofday(&current, NULL);
>
>       spec->tv_sec = current.tv_sec + timer / 1000;
>
>       spec->tv_nsec = (current.tv_usec + (timer % 1000) * 1000) * 1000;
>
> #endif
>
>       return spec;
>
> }
>
>
>
> changhe it to
>
>
>
>
>
> timespec *getTimeout(struct timespec *spec, timeout_t timer)
>
> {
>
>       static  struct timespec myspec;
>
>
>
>       if(spec == NULL)
>
>               spec = &myspec;
>
>
>
> #ifdef        PTHREAD_GET_EXPIRATION_NP
>
>       struct timespec offset;
>
>
>
>       offset.tv_sec = timer / 1000;
>
>       offset.tv_nsec = (timer % 1000) * 1000000;
>
>       pthread_get_expiration_np(&offset, sec);
>
> #else
>
>       struct timeval current;
>
>
>
>       gettimeofday(&current, NULL);
>
>       spec->tv_sec = current.tv_sec + timer / 1000;
>
>       spec->tv_nsec = (current.tv_usec + (timer % 1000) * 1000) * 1000;
>
>   while (spec->tv_nsec >=1000000000)
>
>     {
>
>      spec->tv_nsec  -= 1000000000;
>
>      spec->tv_sec  += 1;
>
>     }
>
> #endif
>
>       return spec;
>
> }
>
>
>
> i have added while loop this prevent pthread_cond_timedwait function to
> exit with EINVAL value.
>
>
>
> thanks for attention and excuse me for my english.
>
> ---------------------------------------------------------
> Stanco dello spam nella tua email? Prova GRATIS
> il nuovo servizio ANTISPAM di superEva:
> http://webmail.supereva.it/spam.html
> ---------------------------------------------------------
>
>
>
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp





reply via email to

[Prev in Thread] Current Thread [Next in Thread]