structs.c 1.17 KB
Newer Older
1
#include <stdbool.h> ///< For boolean constants
2
#include <signal.h>
3 4 5 6 7 8 9 10 11 12

#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
13
typedef struct fb_arc_set {
14
    bool valid;
15
    int edge_num;
16
    edge_t edges[SET_MAX_SIZE];
17
} fb_arc_set_t;
18 19 20

/// Struct for the circular buffer
typedef struct buffer {
21 22 23
    bool finished;
    short best_arc_len;
    fb_arc_set_t sets[BUFF_SIZE];
24 25
} buffer_t;

26
static bool terminate = false;
27 28
static int buffer_shmfd;
static buffer_t *circ_buffer;
29 30 31

/**
 * @brief Function to execute when the program gets a signal
32 33
 * @details Flips the terminate variable to true
 * @param signo
34 35
 * @return none
 **/
36
static void signal_handler(int signo) {
37 38 39 40 41
    terminate = true;
}

/**
 * @brief Function to process the signals passed by the user
42
 * @details Creates a new sigaction structure
43 44 45 46 47 48 49 50 51 52 53
 *          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);
}