aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/core/pcm_native.c73
1 files changed, 20 insertions, 53 deletions
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 59e5fbe6af51..561d6d95a2d3 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1387,11 +1387,6 @@ static struct action_ops snd_pcm_action_drain_init = {
1387 .post_action = snd_pcm_post_drain_init 1387 .post_action = snd_pcm_post_drain_init
1388}; 1388};
1389 1389
1390struct drain_rec {
1391 struct snd_pcm_substream *substream;
1392 wait_queue_t wait;
1393};
1394
1395static int snd_pcm_drop(struct snd_pcm_substream *substream); 1390static int snd_pcm_drop(struct snd_pcm_substream *substream);
1396 1391
1397/* 1392/*
@@ -1407,10 +1402,9 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
1407 struct snd_card *card; 1402 struct snd_card *card;
1408 struct snd_pcm_runtime *runtime; 1403 struct snd_pcm_runtime *runtime;
1409 struct snd_pcm_substream *s; 1404 struct snd_pcm_substream *s;
1405 wait_queue_t wait;
1410 int result = 0; 1406 int result = 0;
1411 int i, num_drecs;
1412 int nonblock = 0; 1407 int nonblock = 0;
1413 struct drain_rec *drec, drec_tmp, *d;
1414 1408
1415 card = substream->pcm->card; 1409 card = substream->pcm->card;
1416 runtime = substream->runtime; 1410 runtime = substream->runtime;
@@ -1433,38 +1427,10 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
1433 } else if (substream->f_flags & O_NONBLOCK) 1427 } else if (substream->f_flags & O_NONBLOCK)
1434 nonblock = 1; 1428 nonblock = 1;
1435 1429
1436 if (nonblock)
1437 goto lock; /* no need to allocate waitqueues */
1438
1439 /* allocate temporary record for drain sync */
1440 down_read(&snd_pcm_link_rwsem); 1430 down_read(&snd_pcm_link_rwsem);
1441 if (snd_pcm_stream_linked(substream)) {
1442 drec = kmalloc(substream->group->count * sizeof(*drec), GFP_KERNEL);
1443 if (! drec) {
1444 up_read(&snd_pcm_link_rwsem);
1445 snd_power_unlock(card);
1446 return -ENOMEM;
1447 }
1448 } else
1449 drec = &drec_tmp;
1450
1451 /* count only playback streams */
1452 num_drecs = 0;
1453 snd_pcm_group_for_each_entry(s, substream) {
1454 runtime = s->runtime;
1455 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1456 d = &drec[num_drecs++];
1457 d->substream = s;
1458 init_waitqueue_entry(&d->wait, current);
1459 add_wait_queue(&runtime->sleep, &d->wait);
1460 }
1461 }
1462 up_read(&snd_pcm_link_rwsem);
1463
1464 lock:
1465 snd_pcm_stream_lock_irq(substream); 1431 snd_pcm_stream_lock_irq(substream);
1466 /* resume pause */ 1432 /* resume pause */
1467 if (substream->runtime->status->state == SNDRV_PCM_STATE_PAUSED) 1433 if (runtime->status->state == SNDRV_PCM_STATE_PAUSED)
1468 snd_pcm_pause(substream, 0); 1434 snd_pcm_pause(substream, 0);
1469 1435
1470 /* pre-start/stop - all running streams are changed to DRAINING state */ 1436 /* pre-start/stop - all running streams are changed to DRAINING state */
@@ -1479,25 +1445,35 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
1479 1445
1480 for (;;) { 1446 for (;;) {
1481 long tout; 1447 long tout;
1448 struct snd_pcm_runtime *to_check;
1482 if (signal_pending(current)) { 1449 if (signal_pending(current)) {
1483 result = -ERESTARTSYS; 1450 result = -ERESTARTSYS;
1484 break; 1451 break;
1485 } 1452 }
1486 /* all finished? */ 1453 /* find a substream to drain */
1487 for (i = 0; i < num_drecs; i++) { 1454 to_check = NULL;
1488 runtime = drec[i].substream->runtime; 1455 snd_pcm_group_for_each_entry(s, substream) {
1489 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) 1456 if (s->stream != SNDRV_PCM_STREAM_PLAYBACK)
1457 continue;
1458 runtime = s->runtime;
1459 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
1460 to_check = runtime;
1490 break; 1461 break;
1462 }
1491 } 1463 }
1492 if (i == num_drecs) 1464 if (!to_check)
1493 break; /* yes, all drained */ 1465 break; /* all drained */
1494 1466 init_waitqueue_entry(&wait, current);
1467 add_wait_queue(&to_check->sleep, &wait);
1495 set_current_state(TASK_INTERRUPTIBLE); 1468 set_current_state(TASK_INTERRUPTIBLE);
1496 snd_pcm_stream_unlock_irq(substream); 1469 snd_pcm_stream_unlock_irq(substream);
1470 up_read(&snd_pcm_link_rwsem);
1497 snd_power_unlock(card); 1471 snd_power_unlock(card);
1498 tout = schedule_timeout(10 * HZ); 1472 tout = schedule_timeout(10 * HZ);
1499 snd_power_lock(card); 1473 snd_power_lock(card);
1474 down_read(&snd_pcm_link_rwsem);
1500 snd_pcm_stream_lock_irq(substream); 1475 snd_pcm_stream_lock_irq(substream);
1476 remove_wait_queue(&to_check->sleep, &wait);
1501 if (tout == 0) { 1477 if (tout == 0) {
1502 if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) 1478 if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED)
1503 result = -ESTRPIPE; 1479 result = -ESTRPIPE;
@@ -1512,16 +1488,7 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
1512 1488
1513 unlock: 1489 unlock:
1514 snd_pcm_stream_unlock_irq(substream); 1490 snd_pcm_stream_unlock_irq(substream);
1515 1491 up_read(&snd_pcm_link_rwsem);
1516 if (!nonblock) {
1517 for (i = 0; i < num_drecs; i++) {
1518 d = &drec[i];
1519 runtime = d->substream->runtime;
1520 remove_wait_queue(&runtime->sleep, &d->wait);
1521 }
1522 if (drec != &drec_tmp)
1523 kfree(drec);
1524 }
1525 snd_power_unlock(card); 1492 snd_power_unlock(card);
1526 1493
1527 return result; 1494 return result;