qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 01/10] Introduce qemu_cond_timedwait for POSIX
Date: Thu, 5 Apr 2012 12:19:33 +0100	[thread overview]
Message-ID: <CAFEAcA_KB5C4zAzGoiUYvFrNzi_xKcVsAG+MQD_xsoqB5mZ98Q@mail.gmail.com> (raw)
In-Reply-To: <6e10c02cbb87fe30703de848455593df41ec7f4b.1333623555.git.jan.kiszka@siemens.com>

On 5 April 2012 11:59, Jan Kiszka <jan.kiszka@siemens.com> 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 ?

-- PMM

  reply	other threads:[~2012-04-05 11:19 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-05 10:59 [Qemu-devel] [PATCH v3 00/10] Use more central threading and synchronization services Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 01/10] Introduce qemu_cond_timedwait for POSIX Jan Kiszka
2012-04-05 11:19   ` Peter Maydell [this message]
2012-04-05 11:56     ` Jan Kiszka
2012-04-05 12:15       ` Peter Maydell
2012-04-05 12:30       ` malc
2012-04-05 12:37         ` Paolo Bonzini
2012-04-05 12:53           ` malc
2012-04-05 12:56             ` Paolo Bonzini
2012-04-05 12:59               ` Jan Kiszka
2012-04-05 13:00                 ` malc
2012-04-05 13:03                   ` Jan Kiszka
2012-04-05 13:20                     ` malc
2012-04-05 13:24                       ` Jan Kiszka
2012-04-05 13:37                         ` malc
2012-04-05 12:59               ` malc
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 02/10] Switch POSIX compat AIO to QEMU abstractions Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 03/10] Switch compatfd to QEMU thread Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 04/10] qemu-thread: Factor out qemu_error_exit Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 05/10] Introduce QemuEvent abstraction Jan Kiszka
2012-04-05 11:23   ` Paolo Bonzini
2012-04-05 12:20     ` Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 06/10] Use QemuEvent in main loop Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 07/10] Drop unused qemu_eventfd Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 08/10] Use QemuEvent for POSIX AIO Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 09/10] virtio: Switch to QemuEvent Jan Kiszka
2012-04-05 10:59 ` [Qemu-devel] [PATCH v3 10/10] Remove EventNotifier Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFEAcA_KB5C4zAzGoiUYvFrNzi_xKcVsAG+MQD_xsoqB5mZ98Q@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=aliguori@us.ibm.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).