PhoenixThread  1.0.0
Tools to ease parallel programming in C++
Loading...
Searching...
No Matches
SignalCatcher.h File Reference
#include <signal.h>
+ Include dependency graph for SignalCatcher.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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)
 

Function Documentation

◆ phoenix_addSignalCatcher()

void phoenix_addSignalCatcher ( int signalType)

Add a signal catcher to handle the given signal.

Parameters
signalType: type of the signal to be handled You should always call this function into your main thread

Definition at line 40 of file SignalCatcher.cpp.

40 {
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}
void phoenix_sig_handler(int signum)
Signal handler.
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.
int expectedSignal
Signal we want to check.

References SignalHandler::expectedSignal, SignalHandler::isSignalRecieved, phoenix_mapSignalHandler, and phoenix_sig_handler().

+ Here is the call graph for this function:

◆ phoenix_isSignalRecived()

bool phoenix_isSignalRecived ( int signalType)

Check if the given signal has been recived by the program (or a thread)

Parameters
signalType: type of signal to check
Returns
true if the signal has been recived, false otherwise

Definition at line 51 of file SignalCatcher.cpp.

51 {
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}

References phoenix_mapSignalHandler.