~ubuntu-branches/ubuntu/natty/plymouth/natty

« back to all changes in this revision

Viewing changes to debian/patches/upstream-event-loop-reference.patch

  • Committer: Colin Watson
  • Date: 2011-03-24 08:49:26 UTC
  • Revision ID: cjwatson@canonical.com-20110324084926-64wbkl0r2wcuvdtk
* Backport from upstream:
  - [event-loop] Add reference count to event sources (with any luck, this
    will fix LP: #553745).
  - [event-loop] Handle more than 8 events at once.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Origin: commit:5daa29168df38b8b5f0f59b0c65a5740082e002a
 
2
Author: Ray Strode <rstrode@redhat.com>
 
3
Subject: [event-loop] Add reference count to event sources
 
4
 
 
5
This prevents the event loop from freeing sources
 
6
early in an iteration of the loop, and then dispatching
 
7
handlers for the source later in that same iteration.
 
8
 
 
9
Index: b/src/libply/ply-event-loop.c
 
10
===================================================================
 
11
--- a/src/libply/ply-event-loop.c
 
12
+++ b/src/libply/ply-event-loop.c
 
13
@@ -56,6 +56,7 @@
 
14
   ply_list_t *fd_watches;
 
15
   uint32_t is_getting_polled : 1;
 
16
   uint32_t is_disconnected : 1;
 
17
+  int reference_count;
 
18
 } ply_event_source_t;
 
19
 
 
20
 typedef struct
 
21
@@ -319,6 +320,12 @@
 
22
   free (watch);
 
23
 }
 
24
 
 
25
+static void
 
26
+ply_event_source_take_reference (ply_event_source_t *source)
 
27
+{
 
28
+  source->reference_count++;
 
29
+}
 
30
+
 
31
 static ply_event_source_t *
 
32
 ply_event_source_new (int fd)
 
33
 {
 
34
@@ -331,6 +338,7 @@
 
35
   source->fd_watches = ply_list_new ();
 
36
   source->is_getting_polled = false;
 
37
   source->is_disconnected = false;
 
38
+  source->reference_count = 0;
 
39
 
 
40
   return source;
 
41
 }
 
42
@@ -349,6 +357,22 @@
 
43
 }
 
44
 
 
45
 static void
 
46
+ply_event_source_drop_reference (ply_event_source_t *source)
 
47
+{
 
48
+  if (source == NULL)
 
49
+    return;
 
50
+
 
51
+  source->reference_count--;
 
52
+
 
53
+  assert (source->reference_count >= 0);
 
54
+
 
55
+  if (source->reference_count == 0)
 
56
+    {
 
57
+      ply_event_source_free (source);
 
58
+    }
 
59
+}
 
60
+
 
61
+static void
 
62
 ply_event_loop_update_source_event_mask (ply_event_loop_t   *loop,
 
63
                                          ply_event_source_t *source)
 
64
 {
 
65
@@ -404,6 +428,7 @@
 
66
   assert (source != NULL);
 
67
 
 
68
   destination->source = source;
 
69
+  ply_event_source_take_reference (source);
 
70
   destination_node = ply_list_append_data (source->destinations, destination);
 
71
   assert (destination_node != NULL);
 
72
   assert (destination->source == source);
 
73
@@ -412,6 +437,7 @@
 
74
 
 
75
   watch = ply_fd_watch_new (destination);
 
76
 
 
77
+  ply_event_source_take_reference (source);
 
78
   ply_list_append_data (source->fd_watches, watch);
 
79
 
 
80
   return watch;
 
81
@@ -449,6 +475,7 @@
 
82
   assert (source != NULL);
 
83
 
 
84
   ply_list_remove_data (source->destinations, destination);
 
85
+  ply_event_source_drop_reference (source);
 
86
   assert (ply_list_find_node (source->destinations, destination) == NULL);
 
87
   ply_event_loop_update_source_event_mask (loop, source);
 
88
 }
 
89
@@ -601,6 +628,7 @@
 
90
 
 
91
   source->is_getting_polled = true;
 
92
 
 
93
+  ply_event_source_take_reference (source);
 
94
   ply_list_append_data (loop->sources, source);
 
95
 }
 
96
 
 
97
@@ -622,6 +650,7 @@
 
98
     }
 
99
 
 
100
   ply_list_remove_node (loop->sources, source_node);
 
101
+  ply_event_source_drop_reference (source);
 
102
 }
 
103
 
 
104
 static void
 
105
@@ -749,6 +778,7 @@
 
106
     {
 
107
       ply_trace ("source for fd %d is already disconnected", source->fd);
 
108
       ply_list_remove_data (source->fd_watches, watch);
 
109
+      ply_event_source_drop_reference (source);
 
110
       ply_fd_watch_free (watch);
 
111
       return;
 
112
     }
 
113
@@ -757,6 +787,7 @@
 
114
   ply_event_loop_remove_destination_by_fd_watch (loop, watch);
 
115
 
 
116
   ply_list_remove_data (source->fd_watches, watch);
 
117
+  ply_event_source_drop_reference (source);
 
118
   ply_fd_watch_free (watch);
 
119
   ply_event_destination_free (destination);
 
120
 
 
121
@@ -764,8 +795,6 @@
 
122
     {
 
123
       ply_trace ("no more destinations remaing for fd %d, removing source", source->fd);
 
124
       ply_event_loop_remove_source (loop, source);
 
125
-      ply_trace ("freeing source for fd %d", source->fd);
 
126
-      ply_event_source_free (source);
 
127
     }
 
128
 }
 
129
 
 
130
@@ -1083,6 +1112,7 @@
 
131
       assert (watch != NULL);
 
132
       ply_fd_watch_free (watch);
 
133
       ply_list_remove_node (source->fd_watches, node);
 
134
+      ply_event_source_drop_reference (source);
 
135
       node = next_node;
 
136
     }
 
137
 }
 
138
@@ -1142,6 +1172,7 @@
 
139
       ply_event_destination_free (destination);
 
140
 
 
141
       ply_list_remove_node (source->destinations, node);
 
142
+      ply_event_source_drop_reference (source);
 
143
       node = next_node;
 
144
     }
 
145
 }
 
146
@@ -1169,9 +1200,6 @@
 
147
   ply_trace ("removing source with fd %d from event loop", source->fd);
 
148
   ply_event_loop_remove_source (loop, source);
 
149
   ply_trace ("done removing source with fd %d from event loop", source->fd);
 
150
-
 
151
-  ply_trace ("freeing source with fd %d", source->fd);
 
152
-  ply_event_source_free (source);
 
153
 }
 
154
 
 
155
 static void
 
156
@@ -1261,6 +1289,19 @@
 
157
     }
 
158
   while ((number_of_received_events < 0) && ((errno == EINTR) || (errno == EAGAIN)));
 
159
 
 
160
+  /* first reference all sources, so they stay alive for the duration of this
 
161
+   * iteration of the loop
 
162
+   */
 
163
+  for (i = 0; i < number_of_received_events; i++)
 
164
+    {
 
165
+      ply_event_source_t *source;
 
166
+      source = (ply_event_source_t *) (events[i].data.ptr);
 
167
+
 
168
+      ply_event_source_take_reference (source);
 
169
+    }
 
170
+
 
171
+  /* Then process the incoming events
 
172
+   */
 
173
   for (i = 0; i < number_of_received_events; i++)
 
174
     {
 
175
       ply_event_source_t *source;
 
176
@@ -1293,6 +1334,17 @@
 
177
       if (loop->should_exit)
 
178
         break;
 
179
     }
 
180
+
 
181
+  /* Finally, kill off any unused sources
 
182
+   */
 
183
+  for (i = 0; i < number_of_received_events; i++)
 
184
+    {
 
185
+      ply_event_source_t *source;
 
186
+
 
187
+      source = (ply_event_source_t *) (events[i].data.ptr);
 
188
+
 
189
+      ply_event_source_drop_reference (source);
 
190
+    }
 
191
 }
 
192
 
 
193
 void