Received: from eggs.gnu.org ([208.118.235.92]:38194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFlps-0001Pn-T6 for qemu-devel@nongnu.org; Thu, 05 Apr 2012 08:30:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFlpm-000642-4N for qemu-devel@nongnu.org; Thu, 05 Apr 2012 08:30:44 -0400 Received: from fe01x03-cgp.akado.ru ([77.232.31.164]:64724 helo=akado.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFlpl-00063R-T8 for qemu-devel@nongnu.org; Thu, 05 Apr 2012 08:30:38 -0400 Date: Thu, 5 Apr 2012 16:30:14 +0400 (MSK) From: malc In-Reply-To: <4F7D887B.1030104@siemens.com> Message-ID: References: <6e10c02cbb87fe30703de848455593df41ec7f4b.1333623555.git.jan.kiszka@siemens.com> <4F7D887B.1030104@siemens.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [Qemu-devel] [PATCH v3 01/10] Introduce qemu_cond_timedwait for POSIX List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Kevin Wolf , Peter Maydell , Anthony Liguori , "qemu-devel@nongnu.org" , Paolo Bonzini On Thu, 5 Apr 2012, Jan Kiszka wrote: > On 2012-04-05 13:19, Peter Maydell wrote: > > On 5 April 2012 11:59, Jan Kiszka 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. > It's probably worth mentioning that using anything other than clock_gettime and CLOCK_MONOTONING (as well as setting proper pthread clock attr on the condition variable) is prone to the surprises (such as NTP corrections and daylight saving changes). -- mailto:av1474@comtv.ru