PhoenixThread  1.0.0
Tools to ease parallel programming in C++
Loading...
Searching...
No Matches
SignalCatcher.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include <map>
8#include <mutex>
9
10#include "SignalCatcher.h"
11
21
23std::map<int, SignalHandler> phoenix_mapSignalHandler;
24
26
28void phoenix_sig_handler(int signum){
29 std::map<int, SignalHandler>::iterator it(phoenix_mapSignalHandler.find(signum));
30 if(it != phoenix_mapSignalHandler.end()){
31 std::lock_guard<std::mutex> guard(it->second.currentMutex);
32 it->second.isSignalRecieved = true;
33 }
34}
35
37
40void phoenix_addSignalCatcher(int signalType){
41 SignalHandler & handler = phoenix_mapSignalHandler[signalType]; //Add the signal to the main map of signals
42 handler.expectedSignal = signalType;
43 handler.isSignalRecieved = false;
44 signal(signalType, phoenix_sig_handler);
45}
46
48
51bool phoenix_isSignalRecived(int signalType){
52 bool b(false);
53 std::map<int, SignalHandler>::iterator it(phoenix_mapSignalHandler.find(signalType));
54 if(it != phoenix_mapSignalHandler.end()){
55 std::lock_guard<std::mutex> guard(it->second.currentMutex);
56 b = it->second.isSignalRecieved;
57 }
58 return b;
59}
60
61
62
63
void phoenix_sig_handler(int signum)
Signal handler.
void phoenix_addSignalCatcher(int signalType)
Add a signal catcher to handle the given signal.
bool phoenix_isSignalRecived(int signalType)
Check if the given signal has been recived by the program (or a thread)
std::map< int, SignalHandler > phoenix_mapSignalHandler
Map of signal handlers.
Handles signal with boolean an mutex.
bool isSignalRecieved
True if the signal has been recived, false otherwise.
std::mutex currentMutex
Mutex of the class to avoid conflict manipulation between threads.
int expectedSignal
Signal we want to check.