kernel/alarm.h (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#ifndef ALARM_H
#define ALARM_H
#include "sched/process.h"
typedef enum {
ALARM_UNDEF = 0,
ALARM_WAKEUP = 1,
ALARM_KILL = 2
} alarm_mode;
struct alarm {
int alarm_id;
int ticks_remaining;
PROCESS_ID pid;
alarm_mode m;
struct alarm *next;
};
/**
* @brief Decrease all alarm counters and act on finished alarms.
*
* This function is called by sched_interrupt_c.
*/
void alarm_tick(void);
/**
* @brief Add a new alarm.
*
* @param ticks Number of ticks to count down.
* @param pid Process ID of the process targeted by the alarm.
* @param m Alarm mode. Defines which action to take once the timer has run out.
*
* @return ID of the created alarm.
*/
int alarm_add(int ticks, PROCESS_ID pid, alarm_mode m);
/**
* @brief Cancel an existing alarm.
*
* @param alarm_id ID of the alarm to be cancelled.
*
* @return 0 on success, -1 if the alarm was not found.
*/
int alarm_cancel(int alarm_id);
#endif