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

#define BUFF_SIZE 8
#define SET_MAX_SIZE 8

/// Struct for the edge
typedef struct edge {
Ivaylo Ivanov's avatar
Ivaylo Ivanov committed
9
    bool chosen;
10 11 12 13
    int u, v;
} edge_t;

/// Struct for the feedback arc set
14
typedef struct fb_arc_set {
15
    bool valid;
16
    int edge_num;
17
    edge_t edges[SET_MAX_SIZE];
18
} fb_arc_set_t;
19 20 21

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

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

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

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