Functions to handle interrupts and timeouts.
More...
#include <setjmp.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "error.h"
Go to the source code of this file.
|
#define | TIMEOUT_DEFAULT 0 |
| The default timeout value. This is the number of seconds before the computation is interrupted.
|
|
#define | LIMIT_DEFAULT 1000000 |
| The default limit value. This is the size of an object above which the computation is interrupted.
|
|
|
void | ignore_timeout (void) |
| Ignores the timeout signal.
|
|
void | listen_timeout (int value) |
| Sets an alarm and listens to the SIGALRM signal.
|
|
void | ignore_interrupt (void) |
| Ignores the interrupt signal.
|
|
void | listen_interrupt (void) |
| Listens to the interrupt signal.
|
|
void | handler (int signum) |
| The interrupt handler.
|
|
void | listening_mode (int value) |
| Listens to all signals (SIGINT and SIGALRM).
|
|
void | normal_mode (void) |
| Ignores all signals and cancel pending alarm, if any.
|
|
|
int | timeout_value |
| The timeout value. It is set to 0 if no timeout is set, and to the number of seconds before the timeout otherwise, by functions that perform long computations in order to be interrupted.
|
|
bool | timeout_flag |
|
unsigned int | limit_value |
| The limit value. It is set to 0 if no limit is set, and to the number of elements of an object before a computation is interrupted otherwise, by functions that perform long computations.
|
|
bool | limit_flag |
|
bool | interrupt_flag |
| The interrupt flag. Indicates if the interrupt signal was received. It is set to true by the interrupt handler and should be checked by the program when it starts long computations, to know if it should stop.
|
|
Functions to handle interrupts and timeouts.
◆ handler()
void handler |
( |
int | signum | ) |
|
The interrupt handler.
- Parameters
-
signum | The signal number. Should be SIGINT. |
◆ listen_timeout()
void listen_timeout |
( |
int | value | ) |
|
Sets an alarm and listens to the SIGALRM signal.
- Parameters
-
value | The number of seconds before the timeout. |
◆ limit_flag
The limit flag. Indicates whether a timeout has occurred. It is checked by the program when it starts long computations, to know whether it should stop.
◆ timeout_flag
The timeout flag. Indicates if a timeout occurred. It is set to true by the timeout handler and should be checked by the program when it starts long computations, to know if it should stop.