Advertisement
Guest User

Native threads deadlock fix

a guest
Dec 27th, 2010
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.75 KB | None | 0 0
  1. From ce9be33ea7a29a73b958a78e1975e3e2e8fdbe49 Mon Sep 17 00:00:00 2001
  2. From: Thomas Jarosch <tomj@simonv.com>
  3. Date: Mon, 27 Dec 2010 07:48:53 -0500
  4. Subject: [PATCH] Fix deadlock on shutdown. Thanks to kugel
  5.  
  6. ---
  7. firmware/target/hosted/sdl/kernel-sdl.c |   24 ++++++++++++++++--------
  8.  1 files changed, 16 insertions(+), 8 deletions(-)
  9.  
  10. diff --git a/firmware/target/hosted/sdl/kernel-sdl.c b/firmware/target/hosted/sdl/kernel-sdl.c
  11. index b4a7c0e..04082fb 100644
  12. --- a/firmware/target/hosted/sdl/kernel-sdl.c
  13. +++ b/firmware/target/hosted/sdl/kernel-sdl.c
  14. @@ -134,14 +134,14 @@ static bool sim_kernel_init(void)
  15.  
  16.  void sim_kernel_shutdown(void)
  17.  {
  18. -    disable_irq();
  19.      SDL_RemoveTimer(tick_timer_id);
  20. -    SDL_DestroyMutex(sim_irq_mtx);
  21. -    SDL_DestroyCond(sim_thread_cond);
  22.  #ifndef HAVE_SDL_THREADS
  23.      do_exit = true;
  24.      SDL_CondSignal(wfi_cond);
  25.  #endif
  26. +    disable_irq();
  27. +    SDL_DestroyMutex(sim_irq_mtx);
  28. +    SDL_DestroyCond(sim_thread_cond);
  29.  }
  30.  
  31.  Uint32 tick_timer(Uint32 interval, void *param)
  32. @@ -150,10 +150,10 @@ Uint32 tick_timer(Uint32 interval, void *param)
  33.  
  34.      (void) interval;
  35.      (void) param;
  36. -    
  37. +
  38.      new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ);
  39. -        
  40. -    while(new_tick != current_tick)
  41. +
  42. +    while(new_tick != current_tick && !do_exit)
  43.      {
  44.          sim_enter_irq_handler();
  45.  
  46. @@ -197,6 +197,14 @@ void wait_for_interrupt(void)
  47.      if (interrupt_level != 0)
  48.          printf("PANIC: Interrupts are disabled!!!\n");
  49.  
  50. +    if (UNLIKELY(do_exit))
  51. +    {
  52. +        SDL_DestroyCond(wfi_cond);
  53. +        SDL_UnlockMutex(wfi_mutex);
  54. +        SDL_DestroyMutex(wfi_mutex);
  55. +        sim_do_exit();
  56. +    }
  57. +
  58.      SDL_CondWait(wfi_cond, wfi_mutex);
  59.  
  60.      if (UNLIKELY(do_exit))
  61. --
  62. 1.7.2.3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement