From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkjB-0000T4-SC for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:19:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFkj5-0004N0-OC for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:19:45 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:41197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFkj5-0004CN-JQ for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:19:39 -0400 Received: by obbup19 with SMTP id up19so1787071obb.4 for ; Thu, 05 Apr 2012 04:19:33 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <6e10c02cbb87fe30703de848455593df41ec7f4b.1333623555.git.jan.kiszka@siemens.com> References: <6e10c02cbb87fe30703de848455593df41ec7f4b.1333623555.git.jan.kiszka@siemens.com> Date: Thu, 5 Apr 2012 12:19:33 +0100 Message-ID: From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 , Paolo Bonzini , Anthony Liguori , qemu-devel@nongnu.org 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, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 unsigned int timeout_ms) > +{ > + =C2=A0 =C2=A0struct timespec ts; > + =C2=A0 =C2=A0struct timeval tv; > + =C2=A0 =C2=A0int err; > + > + =C2=A0 =C2=A0gettimeofday(&tv, NULL); > + =C2=A0 =C2=A0ts.tv_sec =3D tv.tv_sec + timeout_ms / 1000; > + =C2=A0 =C2=A0ts.tv_nsec =3D tv.tv_usec * 1000 + timeout_ms % 1000; > + =C2=A0 =C2=A0if (ts.tv_nsec > 1000000000) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0ts.tv_sec++; > + =C2=A0 =C2=A0 =C2=A0 =C2=A0ts.tv_nsec -=3D 1000000000; > + =C2=A0 =C2=A0} > + =C2=A0 =C2=A0err =3D pthread_cond_timedwait(&cond->cond, &mutex->lock, = &ts); Use clock_gettime() and avoid the need to convert a struct timeval to a struct timespec ? -- PMM