2019-01-12 11:39:01 +00:00
|
|
|
#include <stdbool.h> ///< For boolean constants
|
2019-01-12 22:00:50 +00:00
|
|
|
#include <signal.h>
|
2019-01-12 11:39:01 +00:00
|
|
|
|
|
|
|
#define BUFF_SIZE 8
|
|
|
|
#define SET_MAX_SIZE 8
|
|
|
|
|
|
|
|
/// Struct for the edge
|
|
|
|
typedef struct edge {
|
2019-01-13 13:49:05 +00:00
|
|
|
bool chosen;
|
2019-01-12 11:39:01 +00:00
|
|
|
int u, v;
|
|
|
|
} edge_t;
|
|
|
|
|
|
|
|
/// Struct for the feedback arc set
|
2019-01-12 22:00:50 +00:00
|
|
|
typedef struct fb_arc_set {
|
2019-01-12 11:39:01 +00:00
|
|
|
bool valid;
|
2019-01-12 22:00:50 +00:00
|
|
|
int edge_num;
|
2019-01-12 11:39:01 +00:00
|
|
|
edge_t edges[SET_MAX_SIZE];
|
2019-01-12 22:00:50 +00:00
|
|
|
} fb_arc_set_t;
|
2019-01-12 11:39:01 +00:00
|
|
|
|
|
|
|
/// Struct for the circular buffer
|
|
|
|
typedef struct buffer {
|
2019-01-12 22:00:50 +00:00
|
|
|
bool finished;
|
|
|
|
short best_arc_len;
|
|
|
|
fb_arc_set_t sets[BUFF_SIZE];
|
2019-01-12 11:39:01 +00:00
|
|
|
} buffer_t;
|
|
|
|
|
2019-01-12 22:00:50 +00:00
|
|
|
static bool terminate = false;
|
2019-01-13 12:18:02 +00:00
|
|
|
static int buffer_shmfd;
|
|
|
|
static buffer_t *circ_buffer;
|
2019-01-12 22:00:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Function to execute when the program gets a signal
|
2019-01-13 12:18:02 +00:00
|
|
|
* @details Flips the terminate variable to true
|
|
|
|
* @param signo
|
2019-01-12 22:00:50 +00:00
|
|
|
* @return none
|
|
|
|
**/
|
2019-01-13 12:18:02 +00:00
|
|
|
static void signal_handler(int signo) {
|
2019-01-12 22:00:50 +00:00
|
|
|
terminate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Function to process the signals passed by the user
|
2019-01-13 12:18:02 +00:00
|
|
|
* @details Creates a new sigaction structure
|
2019-01-12 22:00:50 +00:00
|
|
|
* and changes the behaviour of the SIGINT and SIGTERM signals
|
|
|
|
* @param none
|
|
|
|
* @return none
|
|
|
|
**/
|
|
|
|
static void process_signal(void){
|
|
|
|
struct sigaction sa;
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
sa.sa_handler = signal_handler;
|
|
|
|
sigaction(SIGINT, &sa, NULL);
|
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
|
|
|
}
|