spinlock: Make sure C and C++ have the same sizeof(k_spinlock) value
If CONFIG_SMP and SPIN_VALIDATE are both not defined the k_spinlock struct will have no members. The result is that in C the sizeof value of struct k_spinlock is 0 and in C++ it is 1. This size difference causes problems when the k_spinlock is embedded into another struct like k_msgq, because C and C++ will have different ideas on the offsets of the members that come after the k_spinlock member. To prevent this we add a 1 byte dummy member to k_spinlock when the user selects C++ support and k_spinlock would otherwise be empty. Signed-off-by: Erwin Rol <erwin@erwinrol.com>
This commit is contained in:
parent
871d132577
commit
e6ffb3fdc4
1 changed files with 17 additions and 0 deletions
|
@ -61,6 +61,23 @@ struct k_spinlock {
|
||||||
*/
|
*/
|
||||||
uintptr_t thread_cpu;
|
uintptr_t thread_cpu;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_CPLUSPLUS) && !defined(CONFIG_SMP) && !defined(SPIN_VALIDATE)
|
||||||
|
/* If CONFIG_SMP and SPIN_VALIDATE are both not defined
|
||||||
|
* the k_spinlock struct will have no members. The result
|
||||||
|
* is that in C sizeof(k_spinlock) is 0 and in C++ it is 1.
|
||||||
|
*
|
||||||
|
* This size difference causes problems when the k_spinlock
|
||||||
|
* is embedded into another struct like k_msgq, because C and
|
||||||
|
* C++ will have different ideas on the offsets of the members
|
||||||
|
* that come after the k_spinlock member.
|
||||||
|
*
|
||||||
|
* To prevent this we add a 1 byte dummy member to k_spinlock
|
||||||
|
* when the user selects C++ support and k_spinlock would
|
||||||
|
* otherwise be empty.
|
||||||
|
*/
|
||||||
|
char dummy;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static ALWAYS_INLINE k_spinlock_key_t k_spin_lock(struct k_spinlock *l)
|
static ALWAYS_INLINE k_spinlock_key_t k_spin_lock(struct k_spinlock *l)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue