[rtems commit] irq-server: Fix race condition on SMP systems

Sebastian Huber sebh at rtems.org
Thu Nov 12 07:53:30 UTC 2015


Module:    rtems
Branch:    master
Commit:    610909fa85dde9278625ce839b98972fa336d06f
Changeset: http://git.rtems.org/rtems/commit/?id=610909fa85dde9278625ce839b98972fa336d06f

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov 11 12:05:22 2015 +0100

irq-server: Fix race condition on SMP systems

---

 c/src/lib/libbsp/shared/src/irq-server.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/c/src/lib/libbsp/shared/src/irq-server.c b/c/src/lib/libbsp/shared/src/irq-server.c
index 3537493..7dee1dc 100644
--- a/c/src/lib/libbsp/shared/src/irq-server.c
+++ b/c/src/lib/libbsp/shared/src/irq-server.c
@@ -57,20 +57,21 @@ static unsigned bsp_interrupt_server_errors;
 
 static void bsp_interrupt_server_trigger(void *arg)
 {
+  rtems_interrupt_lock_context lock_context;
   bsp_interrupt_server_entry *e = arg;
 
   bsp_interrupt_vector_disable(e->vector);
 
-  if (rtems_chain_is_node_off_chain(&e->node)) {
-    rtems_interrupt_lock_context lock_context;
+  rtems_interrupt_lock_acquire(&bsp_interrupt_server_lock, &lock_context);
 
-    rtems_interrupt_lock_acquire(&bsp_interrupt_server_lock, &lock_context);
+  if (rtems_chain_is_node_off_chain(&e->node)) {
     rtems_chain_append_unprotected(&bsp_interrupt_server_chain, &e->node);
-    rtems_interrupt_lock_release(&bsp_interrupt_server_lock, &lock_context);
   } else {
     ++bsp_interrupt_server_errors;
   }
 
+  rtems_interrupt_lock_release(&bsp_interrupt_server_lock, &lock_context);
+
   rtems_event_system_send(bsp_interrupt_server_id, RTEMS_EVENT_SYSTEM_SERVER);
 }
 




More information about the vc mailing list