Changeset fdb990bd55f690131f00a443f187577fc82c8aa6
- Timestamp:
- 01/21/08 21:35:19
(8 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1200947719 +0000
- git-parent:
[d9b511137a52356cbf7941abd1e6a46ea078f9bc]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1200947719 +0000
- Message:
Remove potential deadlocks in waitpipe with net_*
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rd9b5111 |
rfdb990b |
|
| 556 | 556 | vlc_spin_lock (&internals->spin); |
|---|
| 557 | 557 | signaled = internals->b_signaled; |
|---|
| 558 | | if ((!signaled) && (internals->pipes[0] == -1)) |
|---|
| | 558 | if (internals->pipes[0] == -1) |
|---|
| 559 | 559 | { |
|---|
| 560 | 560 | internals->pipes[0] = pfd[0]; |
|---|
| 561 | 561 | internals->pipes[1] = pfd[1]; |
|---|
| 562 | 562 | } |
|---|
| | 563 | else |
|---|
| | 564 | race = VLC_TRUE; |
|---|
| 563 | 565 | } |
|---|
| 564 | 566 | vlc_spin_unlock (&internals->spin); |
|---|
| 565 | 567 | |
|---|
| 566 | | if (race || signaled) |
|---|
| 567 | | { |
|---|
| | 568 | if (race) |
|---|
| | 569 | { /* Race condition: two threads call pipe() - unlikely */ |
|---|
| 568 | 570 | close (pfd[0]); |
|---|
| 569 | 571 | close (pfd[1]); |
|---|
| 570 | | |
|---|
| 571 | | if (signaled) |
|---|
| 572 | | { /* vlc_object_signal() was already invoked! */ |
|---|
| 573 | | errno = EINTR; |
|---|
| 574 | | return -1; |
|---|
| 575 | | } |
|---|
| 576 | | } |
|---|
| | 572 | } |
|---|
| | 573 | |
|---|
| | 574 | if (signaled) |
|---|
| | 575 | /* Race condition: lc_object_signal() already invoked! */ |
|---|
| | 576 | while (write (internals->pipes[1], &(char){ 0 }, 1) < 0); |
|---|
| 577 | 577 | |
|---|
| 578 | 578 | return internals->pipes[0]; |
|---|
| r98a7a01 |
rfdb990b |
|
| 259 | 259 | * Reads from a network socket. |
|---|
| 260 | 260 | * If waitall is true, then we repeat until we have read the right amount of |
|---|
| 261 | | * data; in that case, a short count means EOF has been reached. |
|---|
| | 261 | * data; in that case, a short count means EOF has been reached or the VLC |
|---|
| | 262 | * object has been signaled. |
|---|
| 262 | 263 | *****************************************************************************/ |
|---|
| 263 | 264 | ssize_t |
|---|
| … | … | |
| 271 | 272 | }; |
|---|
| 272 | 273 | |
|---|
| 273 | | vlc_object_lock (p_this); |
|---|
| 274 | | ufd[1].fd = vlc_object_waitpipe (p_this); |
|---|
| 275 | | |
|---|
| 276 | 274 | while (i_buflen > 0) |
|---|
| 277 | 275 | { |
|---|
| 278 | 276 | int val; |
|---|
| 279 | 277 | |
|---|
| 280 | | if (!vlc_object_alive (p_this)) |
|---|
| 281 | | { |
|---|
| 282 | | #if defined(WIN32) || defined(UNDER_CE) |
|---|
| 283 | | WSASetLastError (WSAEINTR); |
|---|
| 284 | | #else |
|---|
| 285 | | errno = EINTR; |
|---|
| 286 | | #endif |
|---|
| 287 | | goto error; |
|---|
| | 278 | ufd[1].fd = vlc_object_waitpipe (p_this); |
|---|
| | 279 | if (ufd[1].fd == -1) |
|---|
| | 280 | { |
|---|
| 288 | 281 | } |
|---|
| 289 | 282 | ufd[0].revents = ufd[1].revents = 0; |
|---|
| 290 | 283 | |
|---|
| 291 | | vlc_object_unlock (p_this); |
|---|
| 292 | 284 | val = poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1); |
|---|
| 293 | | vlc_object_lock (p_this); |
|---|
| 294 | 285 | |
|---|
| 295 | 286 | if (val < 0) |
|---|
| … | … | |
| 299 | 290 | { |
|---|
| 300 | 291 | msg_Dbg (p_this, "socket %d polling interrupted", fd); |
|---|
| 301 | | vlc_object_wait (p_this); |
|---|
| 302 | | msg_Dbg (p_this, "socket %d polling restarting", fd); |
|---|
| 303 | | continue; |
|---|
| | 292 | if (i_total == 0) |
|---|
| | 293 | { |
|---|
| | 294 | #if defined(WIN32) || defined(UNDER_CE) |
|---|
| | 295 | WSASetLastError (WSAEINTR); |
|---|
| | 296 | #else |
|---|
| | 297 | errno = EINTR; |
|---|
| | 298 | #endif |
|---|
| | 299 | goto error; |
|---|
| | 300 | } |
|---|
| | 301 | break; |
|---|
| 304 | 302 | } |
|---|
| 305 | 303 | |
|---|
| … | … | |
| 379 | 377 | } |
|---|
| 380 | 378 | |
|---|
| 381 | | vlc_object_unlock (p_this); |
|---|
| 382 | 379 | return i_total; |
|---|
| 383 | 380 | |
|---|
| 384 | 381 | error: |
|---|
| 385 | 382 | msg_Err (p_this, "Read error: %m"); |
|---|
| 386 | | |
|---|
| 387 | | vlc_object_unlock (p_this); |
|---|
| 388 | 383 | return -1; |
|---|
| 389 | 384 | } |
|---|
| rcc227c7 |
rfdb990b |
|
| 287 | 287 | assert( pi_fd != NULL ); |
|---|
| 288 | 288 | |
|---|
| 289 | | vlc_object_lock (p_this); |
|---|
| 290 | 289 | evfd = vlc_object_waitpipe (p_this); |
|---|
| 291 | 290 | |
|---|
| 292 | | while (vlc_object_alive (p_this)) |
|---|
| | 291 | for (;;) |
|---|
| 293 | 292 | { |
|---|
| 294 | 293 | unsigned n = 0; |
|---|
| … | … | |
| 304 | 303 | ufd[i].revents = 0; |
|---|
| 305 | 304 | } |
|---|
| 306 | | |
|---|
| 307 | | vlc_object_unlock (p_this); |
|---|
| | 305 | if (evfd == -1) |
|---|
| | 306 | n--; /* avoid EBADF */ |
|---|
| | 307 | |
|---|
| 308 | 308 | switch (poll (ufd, n, timeout)) |
|---|
| 309 | 309 | { |
|---|
| … | … | |
| 314 | 314 | return -1; /* NOTE: p_this already unlocked */ |
|---|
| 315 | 315 | } |
|---|
| 316 | | vlc_object_lock (p_this); |
|---|
| 317 | 316 | |
|---|
| 318 | 317 | if (ufd[n].revents) |
|---|
| 319 | 318 | { |
|---|
| 320 | | vlc_object_wait (p_this); |
|---|
| 321 | 319 | errno = EINTR; |
|---|
| 322 | 320 | break; |
|---|
| … | … | |
| 339 | 337 | memmove (pi_fd + i, pi_fd + i + 1, n - (i + 1)); |
|---|
| 340 | 338 | pi_fd[n - 1] = sfd; |
|---|
| 341 | | vlc_object_unlock (p_this); |
|---|
| 342 | 339 | return fd; |
|---|
| 343 | 340 | } |
|---|
| 344 | 341 | } |
|---|
| 345 | | vlc_object_unlock (p_this); |
|---|
| 346 | 342 | return -1; |
|---|
| 347 | 343 | } |
|---|