qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v3 01/10] Introduce qemu_cond_timedwait for POSI


From: Jan Kiszka
Subject: Re: [Qemu-devel] [PATCH v3 01/10] Introduce qemu_cond_timedwait for POSIX
Date: Thu, 05 Apr 2012 13:56:43 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

On 2012-04-05 13:19, Peter Maydell wrote:
> On 5 April 2012 11:59, Jan Kiszka <address@hidden> wrote:
>> +/* Returns true if condition was signals, false if timed out. */
>> +bool qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex,
>> +                         unsigned int timeout_ms)
>> +{
>> +    struct timespec ts;
>> +    struct timeval tv;
>> +    int err;
>> +
>> +    gettimeofday(&tv, NULL);
>> +    ts.tv_sec = tv.tv_sec + timeout_ms / 1000;
>> +    ts.tv_nsec = tv.tv_usec * 1000 + timeout_ms % 1000;
>> +    if (ts.tv_nsec > 1000000000) {
>> +        ts.tv_sec++;
>> +        ts.tv_nsec -= 1000000000;
>> +    }
>> +    err = pthread_cond_timedwait(&cond->cond, &mutex->lock, &ts);
> 
> Use clock_gettime() and avoid the need to convert a struct timeval
> to a struct timespec ?

Would save that "* 1000". I just wondered why we do not use it elsewhere
in QEMU and was reluctant to risk some BSD breakage.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



reply via email to

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