diff options
-rw-r--r-- | xbmc/Application.cpp | 9 | ||||
-rw-r--r-- | xbmc/platform/darwin/PlatformDarwin.cpp | 3 | ||||
-rw-r--r-- | xbmc/platform/darwin/PlatformDarwin.h | 4 | ||||
-rw-r--r-- | xbmc/platform/overrides/android/PlatformAndroid.cpp | 3 | ||||
-rw-r--r-- | xbmc/platform/overrides/android/PlatformAndroid.h | 4 | ||||
-rw-r--r-- | xbmc/platform/overrides/freebsd/PlatformPosix.cpp | 14 | ||||
-rw-r--r-- | xbmc/platform/overrides/linux/PlatformPosix.cpp | 14 | ||||
-rw-r--r-- | xbmc/platform/posix/CMakeLists.txt | 5 | ||||
-rw-r--r-- | xbmc/platform/posix/PlatformPosix.cpp | 28 | ||||
-rw-r--r-- | xbmc/platform/posix/PlatformPosix.h | 25 | ||||
-rw-r--r-- | xbmc/platform/posix/main.cpp | 26 |
11 files changed, 107 insertions, 28 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 8fef9e5bb4..3bd24ef87b 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -171,6 +171,7 @@ #include "XHandle.h" #include "XTimeUtils.h" #include "platform/posix/filesystem/PosixDirectory.h" +#include "platform/posix/PlatformPosix.h" #endif #if defined(TARGET_ANDROID) @@ -4106,6 +4107,14 @@ void CApplication::ProcessSlow() CheckShutdown(); } +#if defined(TARGET_POSIX) + if (CPlatformPosix::TestShutdownFlag()) + { + CLog::Log(LOGNOTICE, "Shutting down due to POSIX signal"); + CApplicationMessenger::GetInstance().PostMsg(TMSG_SHUTDOWN); + } +#endif + // check if we should restart the player CheckDelayedPlayerRestart(); diff --git a/xbmc/platform/darwin/PlatformDarwin.cpp b/xbmc/platform/darwin/PlatformDarwin.cpp index 1306811d8c..2c5d97ab52 100644 --- a/xbmc/platform/darwin/PlatformDarwin.cpp +++ b/xbmc/platform/darwin/PlatformDarwin.cpp @@ -22,5 +22,6 @@ CPlatformDarwin::~CPlatformDarwin() void CPlatformDarwin::Init() { - setenv("SSL_CERT_FILE", CSpecialProtocol::TranslatePath("special://xbmc/system/certs/cacert.pem").c_str(), 0); + CPlatformPosix::Init(); + setenv("SSL_CERT_FILE", CSpecialProtocol::TranslatePath("special://xbmc/system/certs/cacert.pem").c_str(), 0); }
\ No newline at end of file diff --git a/xbmc/platform/darwin/PlatformDarwin.h b/xbmc/platform/darwin/PlatformDarwin.h index 8597a4d97a..cf77821ff4 100644 --- a/xbmc/platform/darwin/PlatformDarwin.h +++ b/xbmc/platform/darwin/PlatformDarwin.h @@ -8,9 +8,9 @@ #pragma once -#include "platform/Platform.h" +#include "platform/posix/PlatformPosix.h" -class CPlatformDarwin : public CPlatform +class CPlatformDarwin : public CPlatformPosix { public: /**\brief C'tor */ diff --git a/xbmc/platform/overrides/android/PlatformAndroid.cpp b/xbmc/platform/overrides/android/PlatformAndroid.cpp index 9f1367d328..3a55634627 100644 --- a/xbmc/platform/overrides/android/PlatformAndroid.cpp +++ b/xbmc/platform/overrides/android/PlatformAndroid.cpp @@ -27,5 +27,6 @@ CPlatformAndroid::~CPlatformAndroid() void CPlatformAndroid::Init() { - setenv("SSL_CERT_FILE", CSpecialProtocol::TranslatePath("special://xbmc/system/certs/cacert.pem").c_str(), 1); + CPlatformPosix::Init(); + setenv("SSL_CERT_FILE", CSpecialProtocol::TranslatePath("special://xbmc/system/certs/cacert.pem").c_str(), 1); } diff --git a/xbmc/platform/overrides/android/PlatformAndroid.h b/xbmc/platform/overrides/android/PlatformAndroid.h index 99b12cddb4..cae3e4b4ce 100644 --- a/xbmc/platform/overrides/android/PlatformAndroid.h +++ b/xbmc/platform/overrides/android/PlatformAndroid.h @@ -8,9 +8,9 @@ #pragma once -#include "platform/Platform.h" +#include "platform/posix/PlatformPosix.h" -class CPlatformAndroid : public CPlatform +class CPlatformAndroid : public CPlatformPosix { public: /**\brief C'tor */ diff --git a/xbmc/platform/overrides/freebsd/PlatformPosix.cpp b/xbmc/platform/overrides/freebsd/PlatformPosix.cpp new file mode 100644 index 0000000000..fa7cf3da05 --- /dev/null +++ b/xbmc/platform/overrides/freebsd/PlatformPosix.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2019 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "platform/posix/PlatformPosix.h" + +CPlatform* CPlatform::CreateInstance() +{ + return new CPlatformPosix(); +} diff --git a/xbmc/platform/overrides/linux/PlatformPosix.cpp b/xbmc/platform/overrides/linux/PlatformPosix.cpp new file mode 100644 index 0000000000..fa7cf3da05 --- /dev/null +++ b/xbmc/platform/overrides/linux/PlatformPosix.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2019 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "platform/posix/PlatformPosix.h" + +CPlatform* CPlatform::CreateInstance() +{ + return new CPlatformPosix(); +} diff --git a/xbmc/platform/posix/CMakeLists.txt b/xbmc/platform/posix/CMakeLists.txt index c7d6f25c56..f7fe6c819c 100644 --- a/xbmc/platform/posix/CMakeLists.txt +++ b/xbmc/platform/posix/CMakeLists.txt @@ -1,4 +1,7 @@ set(SOURCES Filesystem.cpp - MessagePrinter.cpp) + MessagePrinter.cpp + PlatformPosix.cpp) + +set(HEADERS PlatformPosix.h) core_add_library(platform_posix) diff --git a/xbmc/platform/posix/PlatformPosix.cpp b/xbmc/platform/posix/PlatformPosix.cpp new file mode 100644 index 0000000000..f5272008fa --- /dev/null +++ b/xbmc/platform/posix/PlatformPosix.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2019 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "PlatformPosix.h" + +std::atomic_flag CPlatformPosix::ms_signalFlag; + +void CPlatformPosix::Init() +{ + // Initialize to "set" state + ms_signalFlag.test_and_set(); +} + +bool CPlatformPosix::TestShutdownFlag() +{ + // Keep set, return true when it was cleared before + return !ms_signalFlag.test_and_set(); +} + +void CPlatformPosix::RequestShutdown() +{ + ms_signalFlag.clear(); +} diff --git a/xbmc/platform/posix/PlatformPosix.h b/xbmc/platform/posix/PlatformPosix.h new file mode 100644 index 0000000000..9b51f06ff8 --- /dev/null +++ b/xbmc/platform/posix/PlatformPosix.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2019 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include <atomic> + +#include "platform/Platform.h" + +class CPlatformPosix : public CPlatform +{ +public: + void Init() override; + + static bool TestShutdownFlag(); + static void RequestShutdown(); + +private: + static std::atomic_flag ms_signalFlag; +}; diff --git a/xbmc/platform/posix/main.cpp b/xbmc/platform/posix/main.cpp index 9abacb7502..f0d8d9ba5e 100644 --- a/xbmc/platform/posix/main.cpp +++ b/xbmc/platform/posix/main.cpp @@ -6,8 +6,8 @@ * See LICENSES/README.md for more information. */ -#include <sys/resource.h> #include <signal.h> +#include <sys/resource.h> #include <cstring> @@ -25,6 +25,7 @@ #include "PlayListPlayer.h" #include "platform/MessagePrinter.h" #include "platform/xbmc.h" +#include "PlatformPosix.h" #include "utils/log.h" #ifdef HAS_LIRC @@ -36,31 +37,14 @@ namespace { -class CPOSIXSignalHandleThread : public CThread -{ -public: - CPOSIXSignalHandleThread() - : CThread("POSIX signal handler") - {} -protected: - void Process() override - { - CMessagePrinter::DisplayMessage("Exiting application"); - KODI::MESSAGING::CApplicationMessenger::GetInstance().PostMsg(TMSG_QUIT); - } -}; - extern "C" { void XBMC_POSIX_HandleSignal(int sig) { - // Spawn handling thread: the current thread that this signal was catched on - // might have been interrupted in a call to PostMsg() while holding a lock - // there, which would lead to a deadlock if PostMsg() was called directly here - // as PostMsg() is not supposed to be reentrant - auto thread = new CPOSIXSignalHandleThread; - thread->Create(true); + // Setting an atomic flag is one of the only useful things that is permitted by POSIX + // in signal handlers + CPlatformPosix::RequestShutdown(); } } |