[En-Nut-Discussion] HANDLE in spibus.h: volatile or not?

Harald Kipp harald.kipp at egnite.de
Mon Mar 9 14:58:11 CET 2015


Uwe,

On 09.03.2015 13:09, Uwe Bonnes wrote:
>>>>>> "Harald" == Harald Kipp <harald.kipp at egnite.de> writes:
> 
>     Harald> However, when calling an external function with a pointer to a
>     Harald> non-constant variable, e.g. NutEventWait(&bus_mutex, 0), the
>     Harald> compiler expects a change of the variable's content. In this
>     Harald> case the volatile keyword is not required.
> 
> hertz:~/devel/ethernut_sf/nut> find -name \*.c | xargs grep "HANDLE vol"|wc
>      17     147    1502
> hertz:~/devel/ethernut_sf/nut> find -name \*.c | xargs grep "ile HANDLE" | wc
>       6      34     368
> It seems that some ethernet driver introduces volatile in context with
> HANDLE and all resulting drivers copied that construct. Should we correct?

I agree. Some earlier code, and copies of it, unnecessarily declare
variables volatile. I remember, that this had been pointed out some
years ago and I regularly stumble upon this.

A warning first: It may not always be as easy as a global search and
replace. Some code directly accesses the handle, e.g.

 arch\avr\dev\twif.c(509): if (icb->tw_mm_mtx == SIGNALED) {

Under certain conditions it can happen, that the removal of the volatile
attribute introduces a new problem. As you can imagine, such
synchronization bugs are very difficult to locate later on.

Nevertheless, removing any unnecessary volatile attribute will
significantly reduce code space and increase the performance.

Regards,

Harald



More information about the En-Nut-Discussion mailing list