From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTTx6-00031Q-M0 for qemu-devel@nongnu.org; Wed, 31 Oct 2012 04:47:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTTx1-0004aR-VY for qemu-devel@nongnu.org; Wed, 31 Oct 2012 04:47:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29583) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTTx1-0004aF-Nj for qemu-devel@nongnu.org; Wed, 31 Oct 2012 04:47:03 -0400 Date: Tue, 30 Oct 2012 19:48:58 +0100 From: Stefan Hajnoczi Message-ID: <20121030184858.GC16674@stefanha-thinkpad.redhat.com> References: <1351260355-19802-1-git-send-email-pbonzini@redhat.com> <1351260355-19802-19-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1351260355-19802-19-git-send-email-pbonzini@redhat.com> Subject: Re: [Qemu-devel] [PATCH 18/25] qemu-thread: add QemuSemaphore List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Fri, Oct 26, 2012 at 04:05:48PM +0200, Paolo Bonzini wrote: > +int qemu_sem_timedwait(QemuSemaphore *sem, int ms) > +{ > + int rc; > + > + if (ms <= 0) { > + /* This is cheaper than sem_timedwait. */ > + rc = sem_trywait(&sem->sem); > + if (rc == -1 && errno == EAGAIN) { > + return -1; > + } > + } else { > + struct timeval tv; > + struct timespec ts; > + gettimeofday(&tv, NULL); > + ts.tv_nsec = tv.tv_usec * 1000 + (ms % 1000) * 1000000; > + ts.tv_sec = tv.tv_sec + ms / 1000; > + if (ts.tv_nsec >= 1000000000) { > + ts.tv_sec++; > + ts.tv_nsec -= 1000000000; > + } > + rc = sem_timedwait(&sem->sem, &ts); > + if (rc == -1 && errno == ETIMEDOUT) { > + return -1; > + } > + } > + if (rc < 0) { > + error_exit(errno, __func__); > + } Forgot to handle EINTR? > + return 0; > +} > + > +void qemu_sem_wait(QemuSemaphore *sem) > +{ > + int rc; > + > + rc = sem_wait(&sem->sem); > + if (rc < 0) { > + error_exit(errno, __func__); > + } EINTR