PhoenixThread  1.0.0
Tools to ease parallel programming in C++
Loading...
Searching...
No Matches
SignalCatcher.cpp File Reference
#include <map>
#include <mutex>
#include "SignalCatcher.h"
+ Include dependency graph for SignalCatcher.cpp:

Go to the source code of this file.

Classes

struct  SignalHandler
 Handles signal with boolean an mutex. More...
 

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)
 
void phoenix_sig_handler (int signum)
 Signal handler.
 

Variables

std::map< int, SignalHandlerphoenix_mapSignalHandler
 Map of signal handlers.
 

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.

◆ phoenix_sig_handler()

void phoenix_sig_handler ( int signum)

Signal handler.

Parameters
signum: recived signal

Definition at line 28 of file SignalCatcher.cpp.

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

References phoenix_mapSignalHandler.

Referenced by phoenix_addSignalCatcher().

+ Here is the caller graph for this function:

Variable Documentation

◆ phoenix_mapSignalHandler

std::map<int, SignalHandler> phoenix_mapSignalHandler

Map of signal handlers.

Definition at line 23 of file SignalCatcher.cpp.

Referenced by phoenix_addSignalCatcher(), phoenix_isSignalRecived(), and phoenix_sig_handler().