From 10081abeb653a6fef4aa735a0f11a48d4d04dc67 Mon Sep 17 00:00:00 2001 From: "Vic (Chun-Ju) Yang" Date: Wed, 8 Jan 2014 15:28:53 +0800 Subject: [PATCH] emulator: Guard interrupt status with mutex lock This prevents an interrupt from being triggered when we happen to be enabling/disabling global interrupt. BUG=chrome-os-partner:19235 TEST=Repeatedly run interrupt test BRANCH=None Change-Id: I0163aff801ddbcee4aedba7a78966d97336c79ca Signed-off-by: Vic (Chun-Ju) Yang Reviewed-on: https://chromium-review.googlesource.com/181920 Reviewed-by: Vincent Palatin --- core/host/task.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/host/task.c b/core/host/task.c index 156aeeed62..e560b4c59d 100644 --- a/core/host/task.c +++ b/core/host/task.c @@ -121,12 +121,16 @@ int in_interrupt_context(void) void interrupt_disable(void) { + pthread_mutex_lock(&interrupt_lock); interrupt_disabled = 1; + pthread_mutex_unlock(&interrupt_lock); } void interrupt_enable(void) { + pthread_mutex_lock(&interrupt_lock); interrupt_disabled = 0; + pthread_mutex_unlock(&interrupt_lock); } static void _task_execute_isr(int sig) @@ -210,9 +214,11 @@ static void task_register_interrupt(void) void task_trigger_test_interrupt(void (*isr)(void)) { - if (interrupt_disabled) - return; pthread_mutex_lock(&interrupt_lock); + if (interrupt_disabled) { + pthread_mutex_unlock(&interrupt_lock); + return; + } /* Suspend current task and excute ISR */ pending_isr = isr;