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

55 lines
1.2 KiB
C
Raw Normal View History

#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 {
2019-01-13 13:49:05 +00:00
bool chosen;
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;
static int buffer_shmfd;
static buffer_t *circ_buffer;
/**
* @brief Function to execute when the program gets a signal
* @details Flips the terminate variable to true
* @param signo
* @return none
**/
static void signal_handler(int signo) {
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);
}