This repository has been archived on 2021-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
unix/fb_arc_set/shared/structs.c

54 lines
1.1 KiB
C

#include <stdbool.h> ///< For boolean constants
#include <signal.h>
#define BUFF_SIZE 8
#define SET_MAX_SIZE 8
/// Struct for the edge
typedef struct edge {
int u, v;
} edge_t;
/// Struct for the feedback arc set
typedef struct fb_arc_set {
bool valid;
int edge_num;
edge_t edges[SET_MAX_SIZE];
} fb_arc_set_t;
/// Struct for the circular buffer
typedef struct buffer {
bool finished;
short best_arc_len;
fb_arc_set_t sets[BUFF_SIZE];
} buffer_t;
static bool terminate = false;
/**
* @brief Function to execute when the program gets a signal
* @details flips the terminate variable to true
* @param none
* @return none
**/
static void signal_handler() {
terminate = true;
}
/**
* @brief Function to process the signals passed by the user
* @details creates a new sigaction structure
* 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);
}
static buffer_t *circ_buffer;