ALSA: pcm_core: Fix wake_up() optimization

This change fixes the "ALSA: pcm_lib - optimize wake_up() calls for PCM I/O"
commit. New sleeping queue is introduced to separate user space and kernel
space wake_ups. runtime->nowake is renamed to twake (transfer wake).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 5417f7d..e2a817e 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -285,8 +285,8 @@
 			return -EPIPE;
 		}
 	}
-	if (!runtime->nowake && avail >= runtime->control->avail_min)
-		wake_up(&runtime->sleep);
+	if (avail >= runtime->control->avail_min)
+		wake_up(runtime->twake ? &runtime->tsleep : &runtime->sleep);
 	return 0;
 }
 
@@ -1692,7 +1692,7 @@
 	long tout;
 
 	init_waitqueue_entry(&wait, current);
-	add_wait_queue(&runtime->sleep, &wait);
+	add_wait_queue(&runtime->tsleep, &wait);
 	for (;;) {
 		if (signal_pending(current)) {
 			err = -ERESTARTSYS;
@@ -1735,7 +1735,7 @@
 			break;
 	}
  _endloop:
-	remove_wait_queue(&runtime->sleep, &wait);
+	remove_wait_queue(&runtime->tsleep, &wait);
 	*availp = avail;
 	return err;
 }
@@ -1794,7 +1794,7 @@
 		goto _end_unlock;
 	}
 
-	runtime->nowake = 1;
+	runtime->twake = 1;
 	while (size > 0) {
 		snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
 		snd_pcm_uframes_t avail;
@@ -1816,7 +1816,7 @@
 		if (frames > cont)
 			frames = cont;
 		if (snd_BUG_ON(!frames)) {
-			runtime->nowake = 0;
+			runtime->twake = 0;
 			snd_pcm_stream_unlock_irq(substream);
 			return -EINVAL;
 		}
@@ -1855,7 +1855,7 @@
 		}
 	}
  _end_unlock:
-	runtime->nowake = 0;
+	runtime->twake = 0;
 	if (xfer > 0 && err >= 0)
 		snd_pcm_update_state(substream, runtime);
 	snd_pcm_stream_unlock_irq(substream);
@@ -2016,7 +2016,7 @@
 		goto _end_unlock;
 	}
 
-	runtime->nowake = 1;
+	runtime->twake = 1;
 	while (size > 0) {
 		snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
 		snd_pcm_uframes_t avail;
@@ -2045,7 +2045,7 @@
 		if (frames > cont)
 			frames = cont;
 		if (snd_BUG_ON(!frames)) {
-			runtime->nowake = 0;
+			runtime->twake = 0;
 			snd_pcm_stream_unlock_irq(substream);
 			return -EINVAL;
 		}
@@ -2078,7 +2078,7 @@
 		xfer += frames;
 	}
  _end_unlock:
-	runtime->nowake = 0;
+	runtime->twake = 0;
 	if (xfer > 0 && err >= 0)
 		snd_pcm_update_state(substream, runtime);
 	snd_pcm_stream_unlock_irq(substream);