Skip to content
Permalink
Browse files

thread_cpu: make it 64-bit compatible

This stores a combination of a pointer and a CPU number in the low
2 bits. On 64-bit systems, the pointer part won't fit in an int.
Let's use uintptr_t for this purpose.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
  • Loading branch information...
Nicolas Pitre authored and nashif committed May 21, 2019
1 parent a58a852 commit 0b5d9f71f2c44fefd4151f0271c7b841abc97aa7
Showing with 3 additions and 3 deletions.
  1. +1 −1 include/spinlock.h
  2. +2 −2 kernel/thread.c
@@ -59,7 +59,7 @@ struct k_spinlock {
/* Stores the thread that holds the lock with the locking CPU
* ID in the bottom two bits.
*/
size_t thread_cpu;
uintptr_t thread_cpu;
#endif
};

@@ -727,7 +727,7 @@ bool z_spin_lock_valid(struct k_spinlock *l)

bool z_spin_unlock_valid(struct k_spinlock *l)
{
if (l->thread_cpu != (_current_cpu->id | (u32_t)_current)) {
if (l->thread_cpu != (_current_cpu->id | (uintptr_t)_current)) {
return false;
}
l->thread_cpu = 0;
@@ -736,7 +736,7 @@ bool z_spin_unlock_valid(struct k_spinlock *l)

void z_spin_lock_set_owner(struct k_spinlock *l)
{
l->thread_cpu = _current_cpu->id | (u32_t)_current;
l->thread_cpu = _current_cpu->id | (uintptr_t)_current;
}

#endif

0 comments on commit 0b5d9f7

Please sign in to comment.
You can’t perform that action at this time.