… | |
… | |
219 | static int |
219 | static int |
220 | linuxaio_get_events_from_ring (EV_P) |
220 | linuxaio_get_events_from_ring (EV_P) |
221 | { |
221 | { |
222 | struct aio_ring *ring = (struct aio_ring *)linuxaio_ctx; |
222 | struct aio_ring *ring = (struct aio_ring *)linuxaio_ctx; |
223 | |
223 | |
224 | unsigned head = ring->head; |
224 | /* the kernel reads and writes both of these variables, */ |
|
|
225 | /* as a C extension, we assume that volatile use here */ |
|
|
226 | /* both makes reads atomic and once-only */ |
|
|
227 | unsigned head = *(volatile unsigned *)&ring->head; |
225 | unsigned tail = *(volatile unsigned *)&ring->tail; |
228 | unsigned tail = *(volatile unsigned *)&ring->tail; |
226 | |
229 | |
227 | if (head == tail) |
230 | if (head == tail) |
228 | return 0; |
231 | return 0; |
229 | |
232 | |
… | |
… | |
243 | { |
246 | { |
244 | linuxaio_parse_events (EV_A_ ring->io_events + head, ring->nr - head); |
247 | linuxaio_parse_events (EV_A_ ring->io_events + head, ring->nr - head); |
245 | linuxaio_parse_events (EV_A_ ring->io_events, tail); |
248 | linuxaio_parse_events (EV_A_ ring->io_events, tail); |
246 | } |
249 | } |
247 | |
250 | |
|
|
251 | /* as an extension to C, we hope that the volatile will makethis atomic and once-only */ |
248 | *(volatile unsigned *)&ring->head = tail; |
252 | *(volatile unsigned *)&ring->head = tail; |
249 | /* make sure kernel can see our new head value - probably not required */ |
253 | /* make sure kernel can see our new head value - probably not required */ |
250 | ECB_MEMORY_FENCE_RELEASE; |
254 | ECB_MEMORY_FENCE_RELEASE; |
251 | |
255 | |
252 | return 1; |
256 | return 1; |