Mescal
Loading...
Searching...
No Matches
interrupt.h File Reference

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.

Macros

#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.
 

Functions

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.
 

Variables

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.
 

Detailed Description

Functions to handle interrupts and timeouts.

Function Documentation

◆ handler()

void handler ( int signum)

The interrupt handler.

Parameters
signumThe signal number. Should be SIGINT.

◆ listen_timeout()

void listen_timeout ( int value)

Sets an alarm and listens to the SIGALRM signal.

Parameters
valueThe number of seconds before the timeout.

Variable Documentation

◆ limit_flag

bool limit_flag
extern

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

bool timeout_flag
extern

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.