LMMS
Loading...
Searching...
No Matches
CarlaProcessUtils.cpp
Go to the documentation of this file.
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
18#include "CarlaProcessUtils.hpp"
19
20// --------------------------------------------------------------------------------------------------------------------
21// process utility classes
22
23#if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
24ScopedAbortCatcher::ScopedAbortCatcher()
25{
26 s_triggered = false;
27 s_oldsig = ::setjmp(s_env) == 0
28 ? std::signal(SIGABRT, sig_handler)
29 : nullptr;
30}
31
32ScopedAbortCatcher::~ScopedAbortCatcher()
33{
34 if (s_oldsig != nullptr && ! s_triggered)
35 std::signal(SIGABRT, s_oldsig);
36}
37
38bool ScopedAbortCatcher::s_triggered = false;
39
40jmp_buf ScopedAbortCatcher::s_env;
41sig_t ScopedAbortCatcher::s_oldsig;
42
43void ScopedAbortCatcher::sig_handler(const int signum)
44{
45 CARLA_SAFE_ASSERT_INT2_RETURN(signum == SIGABRT, signum, SIGABRT,);
46
47 s_triggered = true;
48 std::signal(signum, s_oldsig);
49 std::longjmp(s_env, 1);
50}
51#endif
52
53// --------------------------------------------------------------------------------------------------------------------
54
55CarlaSignalRestorer::CarlaSignalRestorer()
56{
57#if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
58 carla_zeroStructs(sigs, 16);
59
60 for (int i=0; i < 16; ++i)
61 ::sigaction(i+1, nullptr, &sigs[i]);
62#endif
63}
64
65CarlaSignalRestorer::~CarlaSignalRestorer()
66{
67#if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
68 for (int i=0; i < 16; ++i)
69 ::sigaction(i+1, &sigs[i], nullptr);
70#endif
71}
72
73// --------------------------------------------------------------------------------------------------------------------
#define CARLA_SAFE_ASSERT_INT2_RETURN(cond, v1, v2, ret)
Definition CarlaDefines.h:207
#define nullptr
Definition DistrhoDefines.h:75
register unsigned i
Definition inflate.c:1575