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.

78 lines
2.1KB

  1. /*
  2. * Carla process utils
  3. * Copyright (C) 2019-2020 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. ScopedAbortCatcher::ScopedAbortCatcher()
  21. {
  22. s_triggered = false;
  23. #ifndef CARLA_OS_WIN
  24. s_oldsig = ::setjmp(s_env) == 0
  25. ? std::signal(SIGABRT, sig_handler)
  26. : nullptr;
  27. #endif
  28. }
  29. ScopedAbortCatcher::~ScopedAbortCatcher()
  30. {
  31. #ifndef CARLA_OS_WIN
  32. if (! s_triggered)
  33. std::signal(SIGABRT, s_oldsig);
  34. #endif
  35. }
  36. bool ScopedAbortCatcher::s_triggered = false;
  37. #ifndef CARLA_OS_WIN
  38. jmp_buf ScopedAbortCatcher::s_env;
  39. sig_t ScopedAbortCatcher::s_oldsig;
  40. void ScopedAbortCatcher::sig_handler(const int signum)
  41. {
  42. CARLA_SAFE_ASSERT_INT2_RETURN(signum == SIGABRT, signum, SIGABRT,);
  43. s_triggered = true;
  44. std::signal(signum, s_oldsig);
  45. std::longjmp(s_env, 1);
  46. }
  47. #endif
  48. // --------------------------------------------------------------------------------------------------------------------
  49. CarlaSignalRestorer::CarlaSignalRestorer()
  50. {
  51. #ifndef CARLA_OS_WIN
  52. carla_zeroStructs(sigs, 16);
  53. for (int i=0; i < 16; ++i)
  54. ::sigaction(i+1, nullptr, &sigs[i]);
  55. #endif
  56. }
  57. CarlaSignalRestorer::~CarlaSignalRestorer()
  58. {
  59. #ifndef CARLA_OS_WIN
  60. for (int i=0; i < 16; ++i)
  61. ::sigaction(i+1, &sigs[i], nullptr);
  62. #endif
  63. }
  64. // --------------------------------------------------------------------------------------------------------------------