kernel: Add interrupt locking to thread monitoring exit API

This is needed because some thread termination paths can be
invoked with no guarantee that thread preemption won't happen.
(It also aligns with the approach taken by the thread monitoring
initialization code.)

Change-Id: I28a384e051775390eb047498cb23fed22910e4df
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
This commit is contained in:
Allan Stephens 2016-10-25 10:57:52 -05:00 committed by Andrew Boie
parent 2220f25f0a
commit 1be7bca333
2 changed files with 8 additions and 10 deletions

View file

@ -148,14 +148,11 @@ void *sys_thread_custom_data_get(void)
#if defined(CONFIG_THREAD_MONITOR)
/*
* Remove a thread from the kernel's list of active threads.
*
* On entry the current thread must be in a non-preemptible state to ensure
* the list of threads does not change in mid-operation. (That is, it must
* be a fiber or interrupts must be locked.) This routine cannot be called
* from an ISR context.
*/
void _thread_monitor_exit(struct tcs *thread)
{
unsigned int key = irq_lock();
if (thread == _nanokernel.threads) {
_nanokernel.threads = _nanokernel.threads->next_thread;
} else {
@ -167,6 +164,8 @@ void _thread_monitor_exit(struct tcs *thread)
}
prev_thread->next_thread = thread->next_thread;
}
irq_unlock(key);
}
#endif /* CONFIG_THREAD_MONITOR */

View file

@ -167,14 +167,11 @@ void *k_thread_custom_data_get(void)
#if defined(CONFIG_THREAD_MONITOR)
/*
* Remove a thread from the kernel's list of active threads.
*
* On entry the current thread must be in a non-preemptible state to ensure
* the list of threads does not change in mid-operation. (That is, it must
* be non-preemptible or have locked the scheduler, or interrupts must be
* locked.) This routine cannot be called from an ISR context.
*/
void _thread_monitor_exit(struct k_thread *thread)
{
unsigned int key = irq_lock();
if (thread == _nanokernel.threads) {
_nanokernel.threads = _nanokernel.threads->next_thread;
} else {
@ -186,6 +183,8 @@ void _thread_monitor_exit(struct k_thread *thread)
}
prev_thread->next_thread = thread->next_thread;
}
irq_unlock(key);
}
#endif /* CONFIG_THREAD_MONITOR */