Commit b04bce47 authored by Andy Walls's avatar Andy Walls Committed by Mauro Carvalho Chehab

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: default avatarAndy Walls <awalls@radix.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 59ba2b00
...@@ -216,7 +216,7 @@ struct cx18_buffer { ...@@ -216,7 +216,7 @@ struct cx18_buffer {
struct cx18_queue { struct cx18_queue {
struct list_head list; struct list_head list;
u32 buffers; atomic_t buffers;
u32 bytesused; u32 bytesused;
}; };
......
...@@ -223,7 +223,7 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block, ...@@ -223,7 +223,7 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block,
prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE);
/* New buffers might have become available before we were added /* New buffers might have become available before we were added
to the waitqueue */ to the waitqueue */
if (!s->q_full.buffers) if (!atomic_read(&s->q_full.buffers))
schedule(); schedule();
finish_wait(&s->waitq, &wait); finish_wait(&s->waitq, &wait);
if (signal_pending(current)) { if (signal_pending(current)) {
...@@ -509,7 +509,7 @@ unsigned int cx18_v4l2_enc_poll(struct file *filp, poll_table *wait) ...@@ -509,7 +509,7 @@ unsigned int cx18_v4l2_enc_poll(struct file *filp, poll_table *wait)
CX18_DEBUG_HI_FILE("Encoder poll\n"); CX18_DEBUG_HI_FILE("Encoder poll\n");
poll_wait(filp, &s->waitq, wait); poll_wait(filp, &s->waitq, wait);
if (s->q_full.buffers || s->q_io.buffers) if (atomic_read(&s->q_full.buffers) || atomic_read(&s->q_io.buffers))
return POLLIN | POLLRDNORM; return POLLIN | POLLRDNORM;
if (eof) if (eof)
return POLLHUP; return POLLHUP;
......
...@@ -731,7 +731,8 @@ static int cx18_log_status(struct file *file, void *fh) ...@@ -731,7 +731,8 @@ static int cx18_log_status(struct file *file, void *fh)
continue; continue;
CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
s->name, s->s_flags, s->name, s->s_flags,
(s->buffers - s->q_free.buffers) * 100 / s->buffers, (s->buffers - atomic_read(&s->q_free.buffers))
* 100 / s->buffers,
(s->buffers * s->buf_size) / 1024, s->buffers); (s->buffers * s->buf_size) / 1024, s->buffers);
} }
CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n", CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
......
...@@ -37,7 +37,7 @@ void cx18_buf_swap(struct cx18_buffer *buf) ...@@ -37,7 +37,7 @@ void cx18_buf_swap(struct cx18_buffer *buf)
void cx18_queue_init(struct cx18_queue *q) void cx18_queue_init(struct cx18_queue *q)
{ {
INIT_LIST_HEAD(&q->list); INIT_LIST_HEAD(&q->list);
q->buffers = 0; atomic_set(&q->buffers, 0);
q->bytesused = 0; q->bytesused = 0;
} }
...@@ -54,7 +54,7 @@ void cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf, ...@@ -54,7 +54,7 @@ void cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf,
} }
spin_lock_irqsave(&s->qlock, flags); spin_lock_irqsave(&s->qlock, flags);
list_add_tail(&buf->list, &q->list); list_add_tail(&buf->list, &q->list);
q->buffers++; atomic_inc(&q->buffers);
q->bytesused += buf->bytesused - buf->readpos; q->bytesused += buf->bytesused - buf->readpos;
spin_unlock_irqrestore(&s->qlock, flags); spin_unlock_irqrestore(&s->qlock, flags);
} }
...@@ -68,7 +68,7 @@ struct cx18_buffer *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q) ...@@ -68,7 +68,7 @@ struct cx18_buffer *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q)
if (!list_empty(&q->list)) { if (!list_empty(&q->list)) {
buf = list_entry(q->list.next, struct cx18_buffer, list); buf = list_entry(q->list.next, struct cx18_buffer, list);
list_del_init(q->list.next); list_del_init(q->list.next);
q->buffers--; atomic_dec(&q->buffers);
q->bytesused -= buf->bytesused - buf->readpos; q->bytesused -= buf->bytesused - buf->readpos;
} }
spin_unlock_irqrestore(&s->qlock, flags); 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,8 +92,8 @@ struct cx18_buffer *cx18_queue_get_buf_irq(struct cx18_stream *s, u32 id,
/* the transport buffers are handled differently, /* the transport buffers are handled differently,
they are not moved to the full queue */ they are not moved to the full queue */
if (s->type != CX18_ENC_STREAM_TYPE_TS) { if (s->type != CX18_ENC_STREAM_TYPE_TS) {
s->q_free.buffers--; atomic_dec(&s->q_free.buffers);
s->q_full.buffers++; atomic_inc(&s->q_full.buffers);
s->q_full.bytesused += buf->bytesused; s->q_full.bytesused += buf->bytesused;
list_move_tail(&buf->list, &s->q_full.list); list_move_tail(&buf->list, &s->q_full.list);
} }
...@@ -119,7 +119,7 @@ static void cx18_queue_flush(struct cx18_stream *s, struct cx18_queue *q) ...@@ -119,7 +119,7 @@ static void cx18_queue_flush(struct cx18_stream *s, struct cx18_queue *q)
buf = list_entry(q->list.next, struct cx18_buffer, list); buf = list_entry(q->list.next, struct cx18_buffer, list);
list_move_tail(q->list.next, &s->q_free.list); list_move_tail(q->list.next, &s->q_free.list);
buf->bytesused = buf->readpos = buf->b_flags = 0; buf->bytesused = buf->readpos = buf->b_flags = 0;
s->q_free.buffers++; atomic_inc(&s->q_free.buffers);
} }
cx18_queue_init(q); cx18_queue_init(q);
spin_unlock_irqrestore(&s->qlock, flags); spin_unlock_irqrestore(&s->qlock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment