diff options
author | Andy Walls <awalls@radix.net> | 2008-08-22 20:03:11 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-10-12 07:36:53 -0400 |
commit | b04bce476c57ac844962462ee4c813c44fa942cf (patch) | |
tree | fb08a484414e6e486fd31c59c8533c46fd4b1341 | |
parent | 59ba2b002265f2e862aa7f0df3f13c09ea99c4da (diff) |
V4L/DVB (8772): cx18: Convert cx18_queue buffers member to atomic_t
cx18: Convert cx18_queue buffers member to atomic_t. This allows safe
concurrent access to check if a queue has data without having to acquire the
queue spinlock.
Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/cx18/cx18-driver.h | 2 | ||||
-rw-r--r-- | drivers/media/video/cx18/cx18-fileops.c | 4 | ||||
-rw-r--r-- | drivers/media/video/cx18/cx18-ioctl.c | 3 | ||||
-rw-r--r-- | drivers/media/video/cx18/cx18-queue.c | 12 |
4 files changed, 11 insertions, 10 deletions
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h index 28c490b1b64..8812a5ec635 100644 --- a/drivers/media/video/cx18/cx18-driver.h +++ b/drivers/media/video/cx18/cx18-driver.h | |||
@@ -216,7 +216,7 @@ struct cx18_buffer { | |||
216 | 216 | ||
217 | struct cx18_queue { | 217 | struct cx18_queue { |
218 | struct list_head list; | 218 | struct list_head list; |
219 | u32 buffers; | 219 | atomic_t buffers; |
220 | u32 bytesused; | 220 | u32 bytesused; |
221 | }; | 221 | }; |
222 | 222 | ||
diff --git a/drivers/media/video/cx18/cx18-fileops.c b/drivers/media/video/cx18/cx18-fileops.c index 2fdbfb994dd..eb0144f9556 100644 --- a/drivers/media/video/cx18/cx18-fileops.c +++ b/drivers/media/video/cx18/cx18-fileops.c | |||
@@ -223,7 +223,7 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block, | |||
223 | prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); | 223 | prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); |
224 | /* New buffers might have become available before we were added | 224 | /* New buffers might have become available before we were added |
225 | to the waitqueue */ | 225 | to the waitqueue */ |
226 | if (!s->q_full.buffers) | 226 | if (!atomic_read(&s->q_full.buffers)) |
227 | schedule(); | 227 | schedule(); |
228 | finish_wait(&s->waitq, &wait); | 228 | finish_wait(&s->waitq, &wait); |
229 | if (signal_pending(current)) { | 229 | if (signal_pending(current)) { |
@@ -509,7 +509,7 @@ unsigned int cx18_v4l2_enc_poll(struct file *filp, poll_table *wait) | |||
509 | CX18_DEBUG_HI_FILE("Encoder poll\n"); | 509 | CX18_DEBUG_HI_FILE("Encoder poll\n"); |
510 | poll_wait(filp, &s->waitq, wait); | 510 | poll_wait(filp, &s->waitq, wait); |
511 | 511 | ||
512 | if (s->q_full.buffers || s->q_io.buffers) | 512 | if (atomic_read(&s->q_full.buffers) || atomic_read(&s->q_io.buffers)) |
513 | return POLLIN | POLLRDNORM; | 513 | return POLLIN | POLLRDNORM; |
514 | if (eof) | 514 | if (eof) |
515 | return POLLHUP; | 515 | return POLLHUP; |
diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c index a7f839631d6..5325c7aacaf 100644 --- a/drivers/media/video/cx18/cx18-ioctl.c +++ b/drivers/media/video/cx18/cx18-ioctl.c | |||
@@ -731,7 +731,8 @@ static int cx18_log_status(struct file *file, void *fh) | |||
731 | continue; | 731 | continue; |
732 | CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", | 732 | CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", |
733 | s->name, s->s_flags, | 733 | s->name, s->s_flags, |
734 | (s->buffers - s->q_free.buffers) * 100 / s->buffers, | 734 | (s->buffers - atomic_read(&s->q_free.buffers)) |
735 | * 100 / s->buffers, | ||
735 | (s->buffers * s->buf_size) / 1024, s->buffers); | 736 | (s->buffers * s->buf_size) / 1024, s->buffers); |
736 | } | 737 | } |
737 | CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n", | 738 | CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n", |
diff --git a/drivers/media/video/cx18/cx18-queue.c b/drivers/media/video/cx18/cx18-queue.c index 4f3bd43ba80..a33ba04a268 100644 --- a/drivers/media/video/cx18/cx18-queue.c +++ b/drivers/media/video/cx18/cx18-queue.c | |||
@@ -37,7 +37,7 @@ void cx18_buf_swap(struct cx18_buffer *buf) | |||
37 | void cx18_queue_init(struct cx18_queue *q) | 37 | void cx18_queue_init(struct cx18_queue *q) |
38 | { | 38 | { |
39 | INIT_LIST_HEAD(&q->list); | 39 | INIT_LIST_HEAD(&q->list); |
40 | q->buffers = 0; | 40 | atomic_set(&q->buffers, 0); |
41 | q->bytesused = 0; | 41 | q->bytesused = 0; |
42 | } | 42 | } |
43 | 43 | ||
@@ -54,7 +54,7 @@ void cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf, | |||
54 | } | 54 | } |
55 | spin_lock_irqsave(&s->qlock, flags); | 55 | spin_lock_irqsave(&s->qlock, flags); |
56 | list_add_tail(&buf->list, &q->list); | 56 | list_add_tail(&buf->list, &q->list); |
57 | q->buffers++; | 57 | atomic_inc(&q->buffers); |
58 | q->bytesused += buf->bytesused - buf->readpos; | 58 | q->bytesused += buf->bytesused - buf->readpos; |
59 | spin_unlock_irqrestore(&s->qlock, flags); | 59 | spin_unlock_irqrestore(&s->qlock, flags); |
60 | } | 60 | } |
@@ -68,7 +68,7 @@ struct cx18_buffer *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q) | |||
68 | if (!list_empty(&q->list)) { | 68 | if (!list_empty(&q->list)) { |
69 | buf = list_entry(q->list.next, struct cx18_buffer, list); | 69 | buf = list_entry(q->list.next, struct cx18_buffer, list); |
70 | list_del_init(q->list.next); | 70 | list_del_init(q->list.next); |
71 | q->buffers--; | 71 | atomic_dec(&q->buffers); |
72 | q->bytesused -= buf->bytesused - buf->readpos; | 72 | q->bytesused -= buf->bytesused - buf->readpos; |
73 | } | 73 | } |
74 | spin_unlock_irqrestore(&s->qlock, flags); | 74 | spin_unlock_irqrestore(&s->qlock, flags); |
@@ -92,8 +92,8 @@ struct cx18_buffer *cx18_queue_get_buf_irq(struct cx18_stream *s, u32 id, | |||
92 | /* the transport buffers are handled differently, | 92 | /* the transport buffers are handled differently, |
93 | they are not moved to the full queue */ | 93 | they are not moved to the full queue */ |
94 | if (s->type != CX18_ENC_STREAM_TYPE_TS) { | 94 | if (s->type != CX18_ENC_STREAM_TYPE_TS) { |
95 | s->q_free.buffers--; | 95 | atomic_dec(&s->q_free.buffers); |
96 | s->q_full.buffers++; | 96 | atomic_inc(&s->q_full.buffers); |
97 | s->q_full.bytesused += buf->bytesused; | 97 | s->q_full.bytesused += buf->bytesused; |
98 | list_move_tail(&buf->list, &s->q_full.list); | 98 | list_move_tail(&buf->list, &s->q_full.list); |
99 | } | 99 | } |
@@ -119,7 +119,7 @@ static void cx18_queue_flush(struct cx18_stream *s, struct cx18_queue *q) | |||
119 | buf = list_entry(q->list.next, struct cx18_buffer, list); | 119 | buf = list_entry(q->list.next, struct cx18_buffer, list); |
120 | list_move_tail(q->list.next, &s->q_free.list); | 120 | list_move_tail(q->list.next, &s->q_free.list); |
121 | buf->bytesused = buf->readpos = buf->b_flags = 0; | 121 | buf->bytesused = buf->readpos = buf->b_flags = 0; |
122 | s->q_free.buffers++; | 122 | atomic_inc(&s->q_free.buffers); |
123 | } | 123 | } |
124 | cx18_queue_init(q); | 124 | cx18_queue_init(q); |
125 | spin_unlock_irqrestore(&s->qlock, flags); | 125 | spin_unlock_irqrestore(&s->qlock, flags); |