diff options
author | Mike Isely <devnull@localhost> | 2006-01-23 06:58:06 +0000 |
---|---|---|
committer | Mike Isely <devnull@localhost> | 2006-01-23 06:58:06 +0000 |
commit | 02770b94ef98488e5f3a2f255ab32bcf6829710d (patch) | |
tree | e0bc4d8d28cdf841a01d6abbe8b020c392234d7d /v4l_experimental/pvrusb2/pvrusb2-io.c | |
parent | 5a0c9ba6e3b1171b5998d194fd5d7d9142f45881 (diff) | |
download | mediapointer-dvb-s2-02770b94ef98488e5f3a2f255ab32bcf6829710d.tar.gz mediapointer-dvb-s2-02770b94ef98488e5f3a2f255ab32bcf6829710d.tar.bz2 |
Use mutexes in pvrusb2 for kernel 2.6.16 or later
From: Mike Isely <isely@pobox.com>
Signed-off-by: Mike Isely <isely@pobox.com>
Diffstat (limited to 'v4l_experimental/pvrusb2/pvrusb2-io.c')
-rw-r--r-- | v4l_experimental/pvrusb2/pvrusb2-io.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/v4l_experimental/pvrusb2/pvrusb2-io.c b/v4l_experimental/pvrusb2/pvrusb2-io.c index c170bede0..d53c63785 100644 --- a/v4l_experimental/pvrusb2/pvrusb2-io.c +++ b/v4l_experimental/pvrusb2/pvrusb2-io.c @@ -1,6 +1,6 @@ /* * - * $Id: pvrusb2-io.c,v 1.2 2006/01/09 06:54:46 mcisely Exp $ + * $Id: pvrusb2-io.c,v 1.3 2006/01/23 06:58:06 mcisely Exp $ * * Copyright (C) 2005 Mike Isely <isely@pobox.com> * @@ -19,12 +19,18 @@ * */ +#include "compat.h" #include "pvrusb2-io.h" #include "pvrusb2-debug.h" #include <linux/errno.h> #include <linux/string.h> #include <linux/slab.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) +#include <asm/atomic.h> +#include <asm/mutex.h> +#else #include <asm/semaphore.h> +#endif #define BUFFER_SIG 0x47653271 @@ -85,7 +91,11 @@ struct pvr2_stream { int endpoint; /* Overhead for mutex enforcement */ spinlock_t list_lock; - struct semaphore sem; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) + struct mutex mutex; +#else + struct semaphore mutex; +#endif /* Tracking state for tolerating errors */ unsigned int fail_count; unsigned int fail_tolerance; @@ -422,7 +432,7 @@ static void pvr2_stream_internal_flush(struct pvr2_stream *sp) static void pvr2_stream_init(struct pvr2_stream *sp) { spin_lock_init(&sp->list_lock); - init_MUTEX(&sp->sem); + mutex_init(&sp->mutex); INIT_LIST_HEAD(&sp->queued_list); INIT_LIST_HEAD(&sp->ready_list); INIT_LIST_HEAD(&sp->idle_list); @@ -430,10 +440,10 @@ static void pvr2_stream_init(struct pvr2_stream *sp) static void pvr2_stream_done(struct pvr2_stream *sp) { - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { pvr2_stream_internal_flush(sp); pvr2_stream_buffer_count(sp,0); - } while (0); up(&sp->sem); + } while (0); mutex_unlock(&sp->mutex); } static void buffer_complete(struct urb *urb, struct pt_regs *regs) @@ -502,12 +512,12 @@ void pvr2_stream_setup(struct pvr2_stream *sp, int endpoint, unsigned int tolerance) { - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { pvr2_stream_internal_flush(sp); sp->dev = dev; sp->endpoint = endpoint; sp->fail_tolerance = tolerance; - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); } void pvr2_stream_set_callback(struct pvr2_stream *sp, @@ -515,12 +525,12 @@ void pvr2_stream_set_callback(struct pvr2_stream *sp, void *data) { unsigned long irq_flags; - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { spin_lock_irqsave(&sp->list_lock,irq_flags); sp->callback_data = data; sp->callback_func = func; spin_unlock_irqrestore(&sp->list_lock,irq_flags); - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); } /* Query / set the nominal buffer count */ @@ -533,10 +543,10 @@ int pvr2_stream_set_buffer_count(struct pvr2_stream *sp,unsigned int cnt) { int ret; if (sp->buffer_target_count == cnt) return 0; - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { sp->buffer_target_count = cnt; ret = pvr2_stream_achieve_buffer_count(sp); - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); return ret; } @@ -573,15 +583,15 @@ int pvr2_stream_get_idle_count(struct pvr2_stream *sp) void pvr2_stream_flush(struct pvr2_stream *sp) { - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { pvr2_stream_internal_flush(sp); - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); } void pvr2_stream_kill(struct pvr2_stream *sp) { struct pvr2_buffer *bp; - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { pvr2_stream_internal_flush(sp); while ((bp = pvr2_stream_get_ready_buffer(sp)) != 0) { pvr2_buffer_set_idle(bp); @@ -589,7 +599,7 @@ void pvr2_stream_kill(struct pvr2_stream *sp) if (sp->buffer_total_count != sp->buffer_target_count) { pvr2_stream_achieve_buffer_count(sp); } - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); } int pvr2_buffer_queue(struct pvr2_buffer *bp) @@ -603,7 +613,7 @@ int pvr2_buffer_queue(struct pvr2_buffer *bp) struct pvr2_stream *sp; if (!bp) return -EINVAL; sp = bp->stream; - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { pvr2_buffer_wipe(bp); if (!sp->dev) { ret = -EIO; @@ -627,7 +637,7 @@ int pvr2_buffer_queue(struct pvr2_buffer *bp) buffer_complete, bp); usb_submit_urb(bp->purb,GFP_KERNEL); - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); return ret; } @@ -636,13 +646,13 @@ int pvr2_buffer_idle(struct pvr2_buffer *bp) struct pvr2_stream *sp; if (!bp) return -EINVAL; sp = bp->stream; - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { pvr2_buffer_wipe(bp); pvr2_buffer_set_idle(bp); if (sp->buffer_total_count != sp->buffer_target_count) { pvr2_stream_achieve_buffer_count(sp); } - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); return 0; } @@ -653,7 +663,7 @@ int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt) struct pvr2_stream *sp; if (!bp) return -EINVAL; sp = bp->stream; - down(&sp->sem); do { + mutex_lock(&sp->mutex); do { spin_lock_irqsave(&sp->list_lock,irq_flags); if (bp->state != pvr2_buffer_state_idle) { ret = -EPERM; @@ -670,7 +680,7 @@ int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt) bp->stream->i_bcount,bp->stream->i_count); } spin_unlock_irqrestore(&sp->list_lock,irq_flags); - } while(0); up(&sp->sem); + } while(0); mutex_unlock(&sp->mutex); return ret; } |