event.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_EVENT_H
10 #define SQUID_SRC_EVENT_H
11 
12 #include "AsyncEngine.h"
13 #include "base/Packable.h"
14 #include "mem/forward.h"
15 
16 /* event scheduling facilities - run a callback after a given time period. */
17 
18 typedef void EVH(void *);
19 
20 void eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata=true);
21 void eventAddIsh(const char *name, EVH * func, void *arg, double delta_ish, int);
22 void eventDelete(EVH * func, void *arg);
23 void eventInit(void);
24 int eventFind(EVH *, void *);
25 
26 class ev_entry
27 {
29 
30 public:
31  ev_entry(char const * name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
32  ~ev_entry();
33  const char *name;
35  void *arg;
36  double when;
37 
38  int weight;
39  bool cbdata;
40 
42 };
43 
44 // manages time-based events
46 {
47 
48 public:
50  ~EventScheduler() override;
51  /* cancel a scheduled but not dispatched event */
52  void cancel(EVH * func, void * arg);
53  /* clean up the used memory in the scheduler */
54  void clean();
55  /* either EVENT_IDLE or milliseconds remaining until the next event */
56  int timeRemaining() const;
57  /* cache manager output for the event queue */
58  void dump(Packable *);
59  /* find a scheduled event */
60  bool find(EVH * func, void * arg);
61  /* schedule a callback function to run in when seconds */
62  void schedule(const char *name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
63  int checkEvents(int timeout) override;
64  static EventScheduler *GetInstance();
65 
66 private:
69 };
70 
71 #endif /* SQUID_SRC_EVENT_H */
72 
EVH * func
Definition: event.h:34
ev_entry * next
Definition: event.h:41
void eventDelete(EVH *func, void *arg)
Definition: event.cc:127
~EventScheduler() override
Definition: event.cc:155
void eventAddIsh(const char *name, EVH *func, void *arg, double delta_ish, int)
Definition: event.cc:114
ev_entry(char const *name, EVH *func, void *arg, double when, int weight, bool cbdata=true)
Definition: event.cc:89
void eventInit(void)
Definition: event.cc:133
void dump(Packable *)
Definition: event.cc:261
EventScheduler()
Definition: event.cc:152
Definition: cbdata.cc:37
bool find(EVH *func, void *arg)
Definition: event.cc:280
static EventScheduler * GetInstance()
Definition: event.cc:294
void * arg
Definition: event.h:35
int timeRemaining() const
Definition: event.cc:199
~ev_entry()
Definition: event.cc:100
Definition: event.h:26
void eventAdd(const char *name, EVH *func, void *arg, double when, int, bool cbdata=true)
Definition: event.cc:107
void schedule(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata=true)
Definition: event.cc:300
void EVH(void *)
Definition: event.h:18
int weight
Definition: event.h:38
double when
Definition: event.h:36
ev_entry * tasks
Definition: event.h:68
void cancel(EVH *func, void *arg)
Definition: event.cc:161
static EventScheduler _instance
Definition: event.h:67
MEMPROXY_CLASS(ev_entry)
const char * name
Definition: event.h:33
bool cbdata
Definition: event.h:39
void clean()
Definition: event.cc:250
int eventFind(EVH *, void *)
Definition: event.cc:145
int checkEvents(int timeout) override
Definition: event.cc:216

 

Introduction

Documentation

Support

Miscellaneous