aboutsummaryrefslogtreecommitdiff
path: root/sim/common/sim-events.h
blob: eb52690ece3677cea68d25ed4b0afd2e76a38d02 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*  This file is part of the program psim.

    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
    */


#ifndef _SIM_EVENTS_H_
#define _SIM_EVENTS_H_


typedef void event_handler(void *data);

typedef struct _event_entry event_entry;
struct _event_entry {
  void *data;
  event_handler *handler;
  signed64 time_of_event;  
  event_entry *next;
};

typedef struct _event_queue event_queue;
struct _event_queue {
  int processing;
  event_entry *queue;
  event_entry *volatile held;
  event_entry *volatile *volatile held_end;
  signed64 time_of_event;
  signed64 time_from_event;
  int trace;
};

typedef struct event_entry *event_entry_tag;


/* Initialization */

INLINE_SIM_EVENTS\
(void) event_queue_init
(engine *system);


/* Tracing level */

INLINE_SIM_EVENTS\
(void) event_queue_trace
(engine *system,
 int level);


/* (de)Schedule things to happen in the future. */

INLINE_SIM_EVENTS\
(event_entry_tag) event_queue_schedule
(engine *system,
 signed64 delta_time,
 event_handler *handler,
 void *data);

INLINE_SIM_EVENTS\
(event_entry_tag) event_queue_schedule_after_signal
(engine *system,
 signed64 delta_time,
 event_handler *handler,
 void *data);

INLINE_SIM_EVENTS\
(void) event_queue_deschedule
(engine *system,
 event_entry_tag event_to_remove);


/* progress time.  Broken into two parts so that if something is
   pending, the caller has a chance to save any cached state */

INLINE_SIM_EVENTS\
(int) event_queue_tick
(engine *system);

INLINE_SIM_EVENTS\
(void) event_queue_process
(engine *system);


/* local concept of time */

INLINE_SIM_EVENTS\
(signed64) event_queue_time
(engine *system);


#endif