xref: /aosp_15_r20/external/cronet/third_party/libevent/chromium.patch (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1diff --git a/third_party/libevent/event.c b/third_party/libevent/event.c
2index da6cd42..36b1c51 100644
3--- a/third_party/libevent/event.c
4+++ b/third_party/libevent/event.c
5@@ -107,11 +107,7 @@ static const struct eventop *eventops[] = {
6 /* Global state */
7 struct event_base *current_base = NULL;
8 extern struct event_base *evsignal_base;
9-static int use_monotonic;
10-
11-/* Handle signals - This is a deprecated interface */
12-int (*event_sigcb)(void);		/* Signal callback when gotsig is set */
13-volatile sig_atomic_t event_gotsig;	/* Set in signal handler */
14+static int use_monotonic = 1;
15
16 /* Prototypes */
17 static void	event_queue_insert(struct event_base *, struct event *, int);
18@@ -124,17 +120,6 @@ static int	timeout_next(struct event_base *, struct timeval **);
19 static void	timeout_process(struct event_base *);
20 static void	timeout_correct(struct event_base *, struct timeval *);
21
22-static void
23-detect_monotonic(void)
24-{
25-#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
26-	struct timespec	ts;
27-
28-	if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
29-		use_monotonic = 1;
30-#endif
31-}
32-
33 static int
34 gettime(struct event_base *base, struct timeval *tp)
35 {
36@@ -144,18 +129,18 @@ gettime(struct event_base *base, struct timeval *tp)
37 	}
38
39 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
40-	if (use_monotonic) {
41-		struct timespec	ts;
42-
43-		if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
44-			return (-1);
45+	struct timespec	ts;
46
47+	if (use_monotonic &&
48+	    clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
49 		tp->tv_sec = ts.tv_sec;
50 		tp->tv_usec = ts.tv_nsec / 1000;
51 		return (0);
52 	}
53 #endif
54
55+	use_monotonic = 0;
56+
57 	return (evutil_gettimeofday(tp, NULL));
58 }
59
60@@ -179,10 +164,6 @@ event_base_new(void)
61 	if ((base = calloc(1, sizeof(struct event_base))) == NULL)
62 		event_err(1, "%s: calloc", __func__);
63
64-	event_sigcb = NULL;
65-	event_gotsig = 0;
66-
67-	detect_monotonic();
68 	gettime(base, &base->event_tv);
69
70 	min_heap_ctor(&base->timeheap);
71@@ -398,12 +379,9 @@ event_process_active(struct event_base *base)
72 			ncalls--;
73 			ev->ev_ncalls = ncalls;
74 			(*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_arg);
75-			if (event_gotsig || base->event_break) {
76-			  	ev->ev_pncalls = NULL;
77+			if (base->event_break)
78 				return;
79-			}
80 		}
81-		ev->ev_pncalls = NULL;
82 	}
83 }
84
85@@ -506,18 +484,6 @@ event_base_loop(struct event_base *base, int flags)
86 			break;
87 		}
88
89-		/* You cannot use this interface for multi-threaded apps */
90-		while (event_gotsig) {
91-			event_gotsig = 0;
92-			if (event_sigcb) {
93-				res = (*event_sigcb)();
94-				if (res == -1) {
95-					errno = EINTR;
96-					return (-1);
97-				}
98-			}
99-		}
100-
101 		timeout_correct(base, &tv);
102
103 		tv_p = &tv;
104@@ -808,8 +774,6 @@ int
105 event_del(struct event *ev)
106 {
107 	struct event_base *base;
108-	const struct eventop *evsel;
109-	void *evbase;
110
111 	event_debug(("event_del: %p, callback %p",
112 		 ev, ev->ev_callback));
113@@ -819,8 +783,6 @@ event_del(struct event *ev)
114 		return (-1);
115
116 	base = ev->ev_base;
117-	evsel = base->evsel;
118-	evbase = base->evbase;
119
120 	assert(!(ev->ev_flags & ~EVLIST_ALL));
121
122@@ -838,7 +800,7 @@ event_del(struct event *ev)
123
124 	if (ev->ev_flags & EVLIST_INSERTED) {
125 		event_queue_remove(base, ev, EVLIST_INSERTED);
126-		return (evsel->del(evbase, ev));
127+		return (base->evsel->del(base->evbase, ev));
128 	}
129
130 	return (0);
131diff --git a/third_party/libevent/event.h b/third_party/libevent/event.h
132index d1f5d9e..f0887b9 100644
133--- a/third_party/libevent/event.h
134+++ b/third_party/libevent/event.h
135@@ -159,7 +159,7 @@
136 extern "C" {
137 #endif
138
139-#include <event-config.h>
140+#include "event-config.h"
141 #ifdef _EVENT_HAVE_SYS_TYPES_H
142 #include <sys/types.h>
143 #endif
144@@ -172,7 +172,7 @@ extern "C" {
145 #include <stdarg.h>
146
147 /* For int types. */
148-#include <evutil.h>
149+#include "evutil.h"
150
151 #ifdef WIN32
152 #define WIN32_LEAN_AND_MEAN
153diff --git a/third_party/libevent/evutil.h b/third_party/libevent/evutil.h
154index dcb0013..8b664b9 100644
155--- a/third_party/libevent/evutil.h
156+++ b/third_party/libevent/evutil.h
157@@ -38,7 +38,7 @@
158 extern "C" {
159 #endif
160
161-#include <event-config.h>
162+#include "event-config.h"
163 #ifdef _EVENT_HAVE_SYS_TIME_H
164 #include <sys/time.h>
165 #endif
166