mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-15 08:16:08 +00:00
feat(Core/SignalHandler): Replace ACE signal handling with std (#4877)
This commit is contained in:
@@ -4,26 +4,41 @@
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#ifndef __SIGNAL_HANDLER_H__
|
||||
#define __SIGNAL_HANDLER_H__
|
||||
#ifndef _SIGNAL_HANDLER_H_
|
||||
#define _SIGNAL_HANDLER_H_
|
||||
|
||||
#include <ace/Event_Handler.h>
|
||||
#include <csignal>
|
||||
#include <unordered_set>
|
||||
#include <mutex>
|
||||
|
||||
namespace acore
|
||||
{
|
||||
|
||||
/// Handle termination signals
|
||||
class SignalHandler : public ACE_Event_Handler
|
||||
class SignalHandler
|
||||
{
|
||||
public:
|
||||
int handle_signal(int SigNum, siginfo_t* = nullptr, ucontext_t* = nullptr) override
|
||||
{
|
||||
HandleSignal(SigNum);
|
||||
return 0;
|
||||
}
|
||||
virtual void HandleSignal(int /*SigNum*/) { };
|
||||
};
|
||||
private:
|
||||
std::unordered_set<int> _handled;
|
||||
mutable std::mutex _mutex;
|
||||
|
||||
public:
|
||||
bool handle_signal(int sig, void (*func)(int))
|
||||
{
|
||||
std::lock_guard lock(_mutex);
|
||||
|
||||
if (_handled.find(sig) != _handled.end())
|
||||
return false;
|
||||
|
||||
_handled.insert(sig);
|
||||
signal(sig, func);
|
||||
return true;
|
||||
}
|
||||
|
||||
~SignalHandler()
|
||||
{
|
||||
for (auto const& sig : _handled)
|
||||
signal(sig, nullptr);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __SIGNAL_HANDLER_H__ */
|
||||
#endif // _SIGNAL_HANDLER_H_
|
||||
|
||||
Reference in New Issue
Block a user