Date: Mon, 10 Jan 2011 00:06:46 +0100 From: Hans Petter Selasky <hselasky@c2i.net> To: Andrew Gallatin <gallatin@gmail.com> Cc: freebsd-multimedia@freebsd.org Subject: Re: em28xx? Message-ID: <201101100006.47252.hselasky@c2i.net> In-Reply-To: <AANLkTin4R_iD1jfHSG5tA73a__JwkfmFY8%2B4ibF8PWY1@mail.gmail.com> References: <AANLkTimhh9qt1mwMk0NJ0_XP2W14azixpKD=fZYYpOpi@mail.gmail.com> <AANLkTim8rAEsmonUvQoQ%2Bt4=K4OqGJ74G7HZW-9onn4Q@mail.gmail.com> <AANLkTin4R_iD1jfHSG5tA73a__JwkfmFY8%2B4ibF8PWY1@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--Boundary-00=_H+jKNwXBcVOqEsx Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit On Sunday 09 January 2011 22:34:20 Andrew Gallatin wrote: > On Sun, Jan 9, 2011 at 3:51 PM, Andrew Gallatin <gallatin@gmail.com> wrote: > > em28xx #0: Successfully loaded em28xx-dvb > > Creating /dev/video0 > > Creating /dev/dvb/adapter0/demux0 > > Creating /dev/dvb/adapter0/dvr0 > > Creating /dev/dvb/adapter0/frontend0 > > A quick test with a natively compiled azap / test_dvr from dvb-utils > shows the tuner to be working fine. Now I just need to figure out > what kind of shims I need to get 32-bit linux binaries working. > > Drew Could you try the attached patch for the recursive locking problem? --HPS --Boundary-00=_H+jKNwXBcVOqEsx Content-Type: text/x-patch; charset="iso-8859-1"; name="webcamd_recursive_locking.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="webcamd_recursive_locking.patch" Index: kernel/linux_thread.c =================================================================== --- kernel/linux_thread.c (revision 1679) +++ kernel/linux_thread.c (working copy) @@ -262,6 +262,7 @@ { memset(sem, 0, sizeof(*sem)); sem->value = value; + sem->owner = MUTEX_NO_OWNER; } void @@ -396,8 +397,8 @@ } struct funcdata { - threadfn_t * volatile func; - void * volatile data; + threadfn_t *volatile func; + void *volatile data; }; struct thread_wrapper { @@ -408,6 +409,7 @@ thread_kill(int dummy) { struct thread_wrapper *pw; + pw = pthread_getspecific(wrapper_key); if (pw != NULL) pw->stopping = 1; @@ -417,6 +419,7 @@ thread_got_stopping(void) { struct thread_wrapper *pw; + pw = pthread_getspecific(wrapper_key); if (pw != NULL) { if (pw->stopping) @@ -476,7 +479,6 @@ free(fd); return (ERR_PTR(-ENOMEM)); } - pthread_mutex_lock(&atomic_mutex); while (fd->func != NULL) pthread_cond_wait(&sema_cond, &atomic_mutex); @@ -574,3 +576,35 @@ { } + +void +mutex_lock(struct mutex *m) +{ + pthread_t self; + + self = pthread_self(); + + atomic_lock(); + /* check for recursive locking first */ + if (m->sem.owner == self) { + m->sem.value--; + } else { + down(&m->sem); + m->sem.owner = self; + } + atomic_unlock(); +} + +void +mutex_unlock(struct mutex *m) +{ + atomic_lock(); + up(&m->sem); + if (m->sem.value > 0) { + /* clear owner variable */ + m->sem.owner = MUTEX_NO_OWNER; + /* guard against double unlock */ + m->sem.value = 1; + } + atomic_unlock(); +} Index: kernel/linux_thread.h =================================================================== --- kernel/linux_thread.h (revision 1680) +++ kernel/linux_thread.h (working copy) @@ -26,6 +26,8 @@ #ifndef _LINUX_THREAD_H_ #define _LINUX_THREAD_H_ +#define MUTEX_NO_OWNER ((pthread_t)-1UL) + typedef struct task_struct { const char *comm; } task_struct_t; @@ -45,9 +47,10 @@ typedef struct semaphore { int32_t value; + pthread_t owner; } semaphore_t; -#define DEFINE_MUTEX(n) struct mutex n = { .sem.value = 1 }; +#define DEFINE_MUTEX(n) struct mutex n = { .sem.value = 1, .sem.owner = MUTEX_NO_OWNER, }; struct mutex { struct semaphore sem; }; @@ -157,11 +160,12 @@ int down_read_trylock(struct semaphore *sem); void poll_wait(struct file *filp, wait_queue_head_t *wq, poll_table * p); +void mutex_lock(struct mutex *m); +void mutex_unlock(struct mutex *m); + #define mutex_init(m) sema_init(&(m)->sem, 1) #define mutex_destroy(m) sema_uninit(&(m)->sem) -#define mutex_lock(m) down(&(m)->sem) -#define mutex_unlock(m) up(&(m)->sem) -#define mutex_lock_interruptible(m) (down(&(m)->sem),0) +#define mutex_lock_interruptible(m) (mutex_lock(m),0) #define init_MUTEX(s) sema_init(s,1) #define init_MUTEX_LOCKED(s) sema_init(s, 0) --Boundary-00=_H+jKNwXBcVOqEsx--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101100006.47252.hselasky>