diff mbox series

[1/2] QSLIST: add atomic replace operation

Message ID 20200824043121.13421-1-wanghonghao@bytedance.com (mailing list archive)
State New, archived
Headers show
Series [1/2] QSLIST: add atomic replace operation | expand

Commit Message

王洪浩 Aug. 24, 2020, 4:31 a.m. UTC
Replace a queue with another atomicly. It's useful when we need to transfer
queues between threads.

Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
---
 include/qemu/queue.h | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Stefan Hajnoczi Aug. 24, 2020, 3:26 p.m. UTC | #1
On Mon, Aug 24, 2020 at 12:31:20PM +0800, wanghonghao wrote:
> Replace a queue with another atomicly. It's useful when we need to transfer
> queues between threads.
> 
> Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
> ---
>  include/qemu/queue.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/include/qemu/queue.h b/include/qemu/queue.h
> index 456a5b01ee..a3ff544193 100644
> --- a/include/qemu/queue.h
> +++ b/include/qemu/queue.h
> @@ -226,6 +226,10 @@ struct {                                                                \
>          (dest)->slh_first = atomic_xchg(&(src)->slh_first, NULL);        \
>  } while (/*CONSTCOND*/0)
>  
> +#define QSLIST_REPLACE_ATOMIC(dest, src) do {                                 \
> +        (src)->slh_first = atomic_xchg(&(dest)->slh_first, (src)->slh_first); \
> +} while (/*CONSTCOND*/0)

This is atomic for dest but not src.

Maybe the name should make this clear: QSLIST_REPLACE_ATOMIC_DEST().

Please also add a doc comment mentioning that the modification to src is
not atomic.

Stefan
王洪浩 Aug. 25, 2020, 3:33 a.m. UTC | #2
This function is indeed a bit vague in semantics.
I'll modify this function to make it more in line with `replace`.

Stefan Hajnoczi <stefanha@redhat.com> 于2020年8月24日周一 下午11:27写道:
>
> On Mon, Aug 24, 2020 at 12:31:20PM +0800, wanghonghao wrote:
> > Replace a queue with another atomicly. It's useful when we need to transfer
> > queues between threads.
> >
> > Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
> > ---
> >  include/qemu/queue.h | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/include/qemu/queue.h b/include/qemu/queue.h
> > index 456a5b01ee..a3ff544193 100644
> > --- a/include/qemu/queue.h
> > +++ b/include/qemu/queue.h
> > @@ -226,6 +226,10 @@ struct {                                                                \
> >          (dest)->slh_first = atomic_xchg(&(src)->slh_first, NULL);        \
> >  } while (/*CONSTCOND*/0)
> >
> > +#define QSLIST_REPLACE_ATOMIC(dest, src) do {                                 \
> > +        (src)->slh_first = atomic_xchg(&(dest)->slh_first, (src)->slh_first); \
> > +} while (/*CONSTCOND*/0)
>
> This is atomic for dest but not src.
>
> Maybe the name should make this clear: QSLIST_REPLACE_ATOMIC_DEST().
>
> Please also add a doc comment mentioning that the modification to src is
> not atomic.
>
> Stefan
diff mbox series

Patch

diff --git a/include/qemu/queue.h b/include/qemu/queue.h
index 456a5b01ee..a3ff544193 100644
--- a/include/qemu/queue.h
+++ b/include/qemu/queue.h
@@ -226,6 +226,10 @@  struct {                                                                \
         (dest)->slh_first = atomic_xchg(&(src)->slh_first, NULL);        \
 } while (/*CONSTCOND*/0)
 
+#define QSLIST_REPLACE_ATOMIC(dest, src) do {                                 \
+        (src)->slh_first = atomic_xchg(&(dest)->slh_first, (src)->slh_first); \
+} while (/*CONSTCOND*/0)
+
 #define QSLIST_REMOVE_HEAD(head, field) do {                             \
         typeof((head)->slh_first) elm = (head)->slh_first;               \
         (head)->slh_first = elm->field.sle_next;                         \