diff mbox series

[PATCH-for-8.0] coroutine: Add missing <qemu/atomic.h> include

Message ID 20221125175532.48858-1-philmd@linaro.org (mailing list archive)
State New, archived
Headers show
Series [PATCH-for-8.0] coroutine: Add missing <qemu/atomic.h> include | expand

Commit Message

Philippe Mathieu-Daudé Nov. 25, 2022, 5:55 p.m. UTC
qemu_co_mutex_assert_locked() calls qatomic_read(), which
is declared in <qemu/atomic.h>. This fixes when refactoring:

  In file included from include/qemu/osdep.h:113,
                   from ../../util/error-report.c:13:
  include/qemu/coroutine.h: In function 'qemu_co_mutex_assert_locked':
  include/qemu/coroutine.h:182:12: error: implicit declaration of function 'qatomic_read' [-Werror=implicit-function-declaration]
    182 |     assert(qatomic_read(&mutex->locked) &&
        |            ^~~~~~~~~~~~

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qemu/coroutine.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Philippe Mathieu-Daudé Dec. 14, 2022, 7:27 a.m. UTC | #1
Cc'ing Markus

On 25/11/22 18:55, Philippe Mathieu-Daudé wrote:
> qemu_co_mutex_assert_locked() calls qatomic_read(), which
> is declared in <qemu/atomic.h>. This fixes when refactoring:
> 
>    In file included from include/qemu/osdep.h:113,
>                     from ../../util/error-report.c:13:
>    include/qemu/coroutine.h: In function 'qemu_co_mutex_assert_locked':
>    include/qemu/coroutine.h:182:12: error: implicit declaration of function 'qatomic_read' [-Werror=implicit-function-declaration]
>      182 |     assert(qatomic_read(&mutex->locked) &&
>          |            ^~~~~~~~~~~~
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/qemu/coroutine.h | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
> index 89650a2d7f..1750c30d8e 100644
> --- a/include/qemu/coroutine.h
> +++ b/include/qemu/coroutine.h
> @@ -17,6 +17,7 @@
>   
>   #include "qemu/queue.h"
>   #include "qemu/timer.h"
> +#include "qemu/atomic.h"
>   
>   /**
>    * Coroutines are a mechanism for stack switching and can be used for
Markus Armbruster Dec. 14, 2022, 7:58 a.m. UTC | #2
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> qemu_co_mutex_assert_locked() calls qatomic_read(), which
> is declared in <qemu/atomic.h>. This fixes when refactoring:
>
>   In file included from include/qemu/osdep.h:113,
>                    from ../../util/error-report.c:13:
>   include/qemu/coroutine.h: In function 'qemu_co_mutex_assert_locked':
>   include/qemu/coroutine.h:182:12: error: implicit declaration of function 'qatomic_read' [-Werror=implicit-function-declaration]
>     182 |     assert(qatomic_read(&mutex->locked) &&
>         |            ^~~~~~~~~~~~
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  include/qemu/coroutine.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
> index 89650a2d7f..1750c30d8e 100644
> --- a/include/qemu/coroutine.h
> +++ b/include/qemu/coroutine.h
> @@ -17,6 +17,7 @@
>  
>  #include "qemu/queue.h"
>  #include "qemu/timer.h"
> +#include "qemu/atomic.h"
>  
>  /**
>   * Coroutines are a mechanism for stack switching and can be used for

I think this papers over the actual problem.

Compiling qemu/coroutine.h by itself succeeds for me.  Printing headers
with -H shows:

    [osdep.h and everything it includes elided...]
    . ../include/qemu/coroutine.h
    .. /work/armbru/qemu/include/qemu/queue.h
    .. /work/armbru/qemu/include/qemu/timer.h
    ... /work/armbru/qemu/include/qemu/bitops.h
    .... /work/armbru/qemu/include/qemu/host-utils.h
    ..... /work/armbru/qemu/include/qemu/bswap.h
    ...... /usr/include/byteswap.h
    ....... /usr/include/bits/byteswap.h
    ..... /work/armbru/qemu/include/qemu/int128.h
    .... /work/armbru/qemu/include/qemu/atomic.h
    [more...]

So, qemu/coroutine.h *already* includes qemu/atomic.h, via qemu/timer.h
and qemu/bitops.h.

I suspect the actual problem is an inclusion loop: qemu/coroutine.h and
qemu/lockable.h include each other.  See my

    Subject: [PATCH 4/4] coroutine: Break inclusion loop
    Message-Id: <20221208142306.2642640-5-armbru@redhat.com>

and Paolo's review.
Philippe Mathieu-Daudé Dec. 14, 2022, 10:28 a.m. UTC | #3
On 14/12/22 08:58, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> qemu_co_mutex_assert_locked() calls qatomic_read(), which
>> is declared in <qemu/atomic.h>. This fixes when refactoring:
>>
>>    In file included from include/qemu/osdep.h:113,
>>                     from ../../util/error-report.c:13:
>>    include/qemu/coroutine.h: In function 'qemu_co_mutex_assert_locked':
>>    include/qemu/coroutine.h:182:12: error: implicit declaration of function 'qatomic_read' [-Werror=implicit-function-declaration]
>>      182 |     assert(qatomic_read(&mutex->locked) &&
>>          |            ^~~~~~~~~~~~
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   include/qemu/coroutine.h | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
>> index 89650a2d7f..1750c30d8e 100644
>> --- a/include/qemu/coroutine.h
>> +++ b/include/qemu/coroutine.h
>> @@ -17,6 +17,7 @@
>>   
>>   #include "qemu/queue.h"
>>   #include "qemu/timer.h"
>> +#include "qemu/atomic.h"
>>   
>>   /**
>>    * Coroutines are a mechanism for stack switching and can be used for
> 
> I think this papers over the actual problem.
> 
> Compiling qemu/coroutine.h by itself succeeds for me.  Printing headers
> with -H shows:
> 
>      [osdep.h and everything it includes elided...]
>      . ../include/qemu/coroutine.h
>      .. /work/armbru/qemu/include/qemu/queue.h
>      .. /work/armbru/qemu/include/qemu/timer.h
>      ... /work/armbru/qemu/include/qemu/bitops.h
>      .... /work/armbru/qemu/include/qemu/host-utils.h
>      ..... /work/armbru/qemu/include/qemu/bswap.h
>      ...... /usr/include/byteswap.h
>      ....... /usr/include/bits/byteswap.h
>      ..... /work/armbru/qemu/include/qemu/int128.h
>      .... /work/armbru/qemu/include/qemu/atomic.h
>      [more...]
> 
> So, qemu/coroutine.h *already* includes qemu/atomic.h, via qemu/timer.h
> and qemu/bitops.h.

Well I'm not sure this implicit dependency is correct, since 
"coroutine.h" explicitly access a function declared in "atomic.h";
if I want to modify "qemu/timer.h" or "qemu/bitops.h" I'm back to
this very patch.

> I suspect the actual problem is an inclusion loop: qemu/coroutine.h and
> qemu/lockable.h include each other.  See my
> 
>      Subject: [PATCH 4/4] coroutine: Break inclusion loop
>      Message-Id: <20221208142306.2642640-5-armbru@redhat.com>
> 
> and Paolo's review.

So I guess I'll wait your series to get merged and see what happens
when I rebase my work on yours.

Thanks,

Phil.
Markus Armbruster Dec. 14, 2022, 2:11 p.m. UTC | #4
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> On 14/12/22 08:58, Markus Armbruster wrote:
>> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
>> 
>>> qemu_co_mutex_assert_locked() calls qatomic_read(), which
>>> is declared in <qemu/atomic.h>. This fixes when refactoring:
>>>
>>>    In file included from include/qemu/osdep.h:113,
>>>                     from ../../util/error-report.c:13:
>>>    include/qemu/coroutine.h: In function 'qemu_co_mutex_assert_locked':
>>>    include/qemu/coroutine.h:182:12: error: implicit declaration of function 'qatomic_read' [-Werror=implicit-function-declaration]
>>>      182 |     assert(qatomic_read(&mutex->locked) &&
>>>          |            ^~~~~~~~~~~~
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> ---
>>>   include/qemu/coroutine.h | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
>>> index 89650a2d7f..1750c30d8e 100644
>>> --- a/include/qemu/coroutine.h
>>> +++ b/include/qemu/coroutine.h
>>> @@ -17,6 +17,7 @@
>>>     #include "qemu/queue.h"
>>>   #include "qemu/timer.h"
>>> +#include "qemu/atomic.h"
>>>     /**
>>>    * Coroutines are a mechanism for stack switching and can be used for
>> I think this papers over the actual problem.
>> Compiling qemu/coroutine.h by itself succeeds for me.  Printing headers
>> with -H shows:
>>      [osdep.h and everything it includes elided...]
>>      . ../include/qemu/coroutine.h
>>      .. /work/armbru/qemu/include/qemu/queue.h
>>      .. /work/armbru/qemu/include/qemu/timer.h
>>      ... /work/armbru/qemu/include/qemu/bitops.h
>>      .... /work/armbru/qemu/include/qemu/host-utils.h
>>      ..... /work/armbru/qemu/include/qemu/bswap.h
>>      ...... /usr/include/byteswap.h
>>      ....... /usr/include/bits/byteswap.h
>>      ..... /work/armbru/qemu/include/qemu/int128.h
>>      .... /work/armbru/qemu/include/qemu/atomic.h
>>      [more...]
>> So, qemu/coroutine.h *already* includes qemu/atomic.h, via qemu/timer.h
>> and qemu/bitops.h.
>
> Well I'm not sure this implicit dependency is correct, since "coroutine.h" explicitly access a function declared in "atomic.h";
> if I want to modify "qemu/timer.h" or "qemu/bitops.h" I'm back to
> this very patch.

We have a rule "every header should include everything it needs".  We
don't have a rule "every header should include everything it needs
directly".

Yes, this means that when you drop includes from a header, you may have
to add them back elsewhere.

>> I suspect the actual problem is an inclusion loop: qemu/coroutine.h and
>> qemu/lockable.h include each other.  See my
>>      Subject: [PATCH 4/4] coroutine: Break inclusion loop
>>      Message-Id: <20221208142306.2642640-5-armbru@redhat.com>
>> and Paolo's review.
>
> So I guess I'll wait your series to get merged and see what happens
> when I rebase my work on yours.

Makes sense to me.
diff mbox series

Patch

diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 89650a2d7f..1750c30d8e 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -17,6 +17,7 @@ 
 
 #include "qemu/queue.h"
 #include "qemu/timer.h"
+#include "qemu/atomic.h"
 
 /**
  * Coroutines are a mechanism for stack switching and can be used for