Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2KB

  1. /*
  2. * Carla process utils
  3. * Copyright (C) 2019-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaProcessUtils.hpp"
  18. // --------------------------------------------------------------------------------------------------------------------
  19. // process utility classes
  20. #if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
  21. ScopedAbortCatcher::ScopedAbortCatcher()
  22. {
  23. s_triggered = false;
  24. s_oldsig = ::setjmp(s_env) == 0
  25. ? std::signal(SIGABRT, sig_handler)
  26. : nullptr;
  27. }
  28. ScopedAbortCatcher::~ScopedAbortCatcher()
  29. {
  30. if (s_oldsig != nullptr && ! s_triggered)
  31. std::signal(SIGABRT, s_oldsig);
  32. }
  33. bool ScopedAbortCatcher::s_triggered = false;
  34. jmp_buf ScopedAbortCatcher::s_env;
  35. sig_t ScopedAbortCatcher::s_oldsig;
  36. void ScopedAbortCatcher::sig_handler(const int signum)
  37. {
  38. CARLA_SAFE_ASSERT_INT2_RETURN(signum == SIGABRT, signum, SIGABRT,);
  39. s_triggered = true;
  40. std::signal(signum, s_oldsig);
  41. std::longjmp(s_env, 1);
  42. }
  43. #endif
  44. // --------------------------------------------------------------------------------------------------------------------
  45. CarlaSignalRestorer::CarlaSignalRestorer()
  46. {
  47. #if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
  48. carla_zeroStructs(sigs, 16);
  49. for (int i=0; i < 16; ++i)
  50. ::sigaction(i+1, nullptr, &sigs[i]);
  51. #endif
  52. }
  53. CarlaSignalRestorer::~CarlaSignalRestorer()
  54. {
  55. #if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
  56. for (int i=0; i < 16; ++i)
  57. ::sigaction(i+1, &sigs[i], nullptr);
  58. #endif
  59. }
  60. // --------------------------------------------------------------------------------------------------------------------