The type of ch.vtlist is virtual_timers_list_t, while vt_next / vt_prev point to virtual_timer_t.
The compiler assumes that a pointer to virtual_timer_t cannot point to a virtual_timers_list_t, as they are different types. This is correct (according to the C standard) compiler behavior.
I already linked this in another thread:
http://dbp-consulting.com/tutorials/StrictAliasing.html
The page mentions a correct solution
An aggregate (struct or class) or union type can alias types contained inside them. (Example: If a function gets passed a pointer to an int, and a pointer to a struct or union containing an int, or possibly containing another struct or union containing an int, or containing...ad infinitum, it's possible that the int* points to an int contained inside the struct or union pointed at by the other pointer.)
Code: Select all
struct ch_virtual_timer_list_node {
virtual_timer_t *vt_next; /**< @brief Next timer in the list. */
virtual_timer_t *vt_prev; /**< @brief Previous timer in the list. */
systime_t vt_delta; /**< @brief Time delta before timeout. */
};
Put that as a member in virtual_timers_list_t and virtual_timer_t and it should work without barriers.