public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Issa Gorissen <flop.m@usa.net>
To: Linux Media Mailing List <linux-media@vger.kernel.org>
Cc: Oliver Endriss <o.endriss@gmx.de>,
	Mauro Carvalho Chehab <mchehab@redhat.com>,
	Ralph Metzler <rjkm@metzlerbros.de>
Subject: Re: Fwd: [PATCH] ngene: blocking and nonblocking io for sec0
Date: Tue, 21 Jun 2011 23:58:48 +0200	[thread overview]
Message-ID: <4E011418.7040601@usa.net> (raw)
In-Reply-To: <201106181307.32895@orion.escape-edv.de>

Haven't fully understood the usage of wake_event_interruptible, now I have read its description. Sorry for the lame patch.

Please find a fixed version below.


Patch allows for blocking or nonblocking io on the ngene sec0 device.
It also enforces one reader and one writer at a time.

Signed-off-by: Issa Gorissen <flop.m@usa.net>
--

--- a/linux/drivers/media/dvb/ngene/ngene-dvb.c	2011-05-10 19:11:21.000000000 +0200
+++ b/linux/drivers/media/dvb/ngene/ngene-dvb.c	2011-06-21 23:46:09.000000000 +0200
@@ -53,15 +53,30 @@ static ssize_t ts_write(struct file *fil
 	struct dvb_device *dvbdev = file->private_data;
 	struct ngene_channel *chan = dvbdev->priv;
 	struct ngene *dev = chan->dev;
+	int avail = 0;
+	char nonblock = file->f_flags & O_NONBLOCK;
 
-	if (wait_event_interruptible(dev->tsout_rbuf.queue,
-				     dvb_ringbuffer_free
-				     (&dev->tsout_rbuf) >= count) < 0)
+	if (!count)
 		return 0;
 
-	dvb_ringbuffer_write(&dev->tsout_rbuf, buf, count);
+	if (nonblock) {
+		avail = dvb_ringbuffer_free(&dev->tsout_rbuf);
+		if (!avail)
+			return -EAGAIN;
+		if (count < avail)
+			avail = count;
+	} else {
+		if (wait_event_interruptible(dev->tsout_rbuf.queue,
+					     dvb_ringbuffer_free
+					     (&dev->tsout_rbuf) >= count) < 0)
+			return -EINTR;
+
+		avail = count;
+	}
+
+	dvb_ringbuffer_write(&dev->tsout_rbuf, buf, avail);
+	return avail;
 
-	return count;
 }
 
 static ssize_t ts_read(struct file *file, char *buf,
@@ -70,22 +85,29 @@ static ssize_t ts_read(struct file *file
 	struct dvb_device *dvbdev = file->private_data;
 	struct ngene_channel *chan = dvbdev->priv;
 	struct ngene *dev = chan->dev;
-	int left, avail;
+	int avail = 0;
+	char nonblock = file->f_flags & O_NONBLOCK;
 
-	left = count;
-	while (left) {
-		if (wait_event_interruptible(
-			    dev->tsin_rbuf.queue,
-			    dvb_ringbuffer_avail(&dev->tsin_rbuf) > 0) < 0)
-			return -EAGAIN;
+	if (!count)
+		return 0;
+
+	if (nonblock) {
 		avail = dvb_ringbuffer_avail(&dev->tsin_rbuf);
-		if (avail > left)
-			avail = left;
-		dvb_ringbuffer_read_user(&dev->tsin_rbuf, buf, avail);
-		left -= avail;
-		buf += avail;
+		if (!avail)
+			return -EAGAIN;
+		if (avail > count)
+			avail = count;
+	} else {
+		if (wait_event_interruptible(dev->tsin_rbuf.queue,
+					     dvb_ringbuffer_avail
+					     (&dev->tsin_rbuf) >= count) < 0)
+			return -EINTR;
+
+		avail = count;
 	}
-	return count;
+
+	dvb_ringbuffer_read_user(&dev->tsin_rbuf, buf, avail);
+	return avail;
 }
 
 static const struct file_operations ci_fops = {
@@ -98,9 +120,9 @@ static const struct file_operations ci_f
 
 struct dvb_device ngene_dvbdev_ci = {
 	.priv    = 0,
-	.readers = -1,
-	.writers = -1,
-	.users   = -1,
+	.readers = 1,
+	.writers = 1,
+	.users   = 2,
 	.fops    = &ci_fops,
 };
 



      reply	other threads:[~2011-06-21 21:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-01 21:01 Fwd: [PATCH] ngene: blocking and nonblocking io for sec0 Mauro Carvalho Chehab
2011-06-18 11:07 ` Oliver Endriss
2011-06-21 21:58   ` Issa Gorissen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E011418.7040601@usa.net \
    --to=flop.m@usa.net \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@redhat.com \
    --cc=o.endriss@gmx.de \
    --cc=rjkm@metzlerbros.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox