[En-Nut-Discussion] HANDLE in spibus.h: volatile or not?
harald.kipp at egnite.de
Mon Mar 9 12:55:19 CET 2015
On 08.03.2015 16:46, Uwe Bonnes wrote:
> 84 /*! \brief Bus lock queue.
> 85 */
> 86 HANDLE bus_mutex;
> 88 /*! \brief Bus wait ready queue.
> 89 */
> 90 HANDLE bus_ready;
> don't contain the volatile keyword.
> It that intentional and the volatile keyword not needed?
> For interrupt driven drivers, normally the interrupt routine signals the
> handle and the user code waits on that handle. As I understand it, this is
> the classic case where "volatile" is needed.
Not exactly. The volatile keyword is required, when the compiler may
misleadingly assume, that a variable content cannot change.
However, when calling an external function with a pointer to a
non-constant variable, e.g. NutEventWait(&bus_mutex, 0), the compiler
expects a change of the variable's content. In this case the volatile
keyword is not required.
You are probably aware, that the volatile keyword makes the code big and
slow and shouldn't be used unnecessarily.
More information about the En-Nut-Discussion