structs.c 1.14 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
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);
}

53
static buffer_t *circ_buffer;