atimer.h 2.12 KB
Newer Older
Gerd Moellmann's avatar
Gerd Moellmann committed
1
/* Asynchronous timers.
Paul Eggert's avatar
Paul Eggert committed
2
   Copyright (C) 2000-2019 Free Software Foundation, Inc.
Gerd Moellmann's avatar
Gerd Moellmann committed
3 4 5

This file is part of GNU Emacs.

6
GNU Emacs is free software: you can redistribute it and/or modify
Gerd Moellmann's avatar
Gerd Moellmann committed
7
it under the terms of the GNU General Public License as published by
8 9
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Gerd Moellmann's avatar
Gerd Moellmann committed
10 11 12 13 14 15 16

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
17
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
18

19 20 21
#ifndef EMACS_ATIMER_H
#define EMACS_ATIMER_H

22
#include <time.h>
23

Gerd Moellmann's avatar
Gerd Moellmann committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37
/* Forward declaration.  */

struct atimer;

/* Types of timers.  */

enum atimer_type
{
  /* Timer is ripe at some absolute time.  */
  ATIMER_ABSOLUTE,

  /* Timer is ripe at now plus an offset.  */
  ATIMER_RELATIVE,

Juanma Barranquero's avatar
Juanma Barranquero committed
38
  /* Timer runs continuously.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
39 40 41 42 43
  ATIMER_CONTINUOUS
};

/* Type of timer callback functions.  */

Jan D's avatar
Jan D committed
44
typedef void (* atimer_callback) (struct atimer *timer);
Gerd Moellmann's avatar
Gerd Moellmann committed
45 46 47 48 49 50 51

/* Structure describing an asynchronous timer.  */

struct atimer
{
  /* The type of this timer.  */
  enum atimer_type type;
52

Gerd Moellmann's avatar
Gerd Moellmann committed
53
  /* Time when this timer is ripe.  */
54
  struct timespec expiration;
Gerd Moellmann's avatar
Gerd Moellmann committed
55 56

  /* Interval of this timer.  */
57
  struct timespec interval;
Gerd Moellmann's avatar
Gerd Moellmann committed
58

Pavel Janík's avatar
Pavel Janík committed
59 60
  /* Function to call when timer is ripe.  Interrupt input is
     guaranteed to not be blocked when this function is called.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
61 62 63 64 65 66 67 68 69 70 71
  atimer_callback fn;

  /* Additional user-specified data to pass to FN.  */
  void *client_data;

  /* Next in list of active or free atimers.  */
  struct atimer *next;
};

/* Function prototypes.  */

72
struct atimer *start_atimer (enum atimer_type, struct timespec,
Jan D's avatar
Jan D committed
73 74 75 76
                             atimer_callback, void *);
void cancel_atimer (struct atimer *);
void do_pending_atimers (void);
void init_atimer (void);
77
void turn_on_atimers (bool);
Jan D's avatar
Jan D committed
78
void stop_other_atimers (struct atimer *);
79
void run_all_atimers (void);
80 81 82
#ifdef HAVE_TIMERFD
void timerfd_callback (int, void *);
#endif
Gerd Moellmann's avatar
Gerd Moellmann committed
83

84
#endif /* EMACS_ATIMER_H */