linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bluez-devel] [PATCH] snd-bt-sco and new mutex API in kernel 2.6.16
@ 2006-03-31 14:08 Whoopie
  2006-04-13 19:50 ` Brad Midgley
  0 siblings, 1 reply; 2+ messages in thread
From: Whoopie @ 2006-03-31 14:08 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 127 bytes --]

Hi,

attached a patch to use the new mutex API introduced in kernel 2.6.16.
It's backwards compatible.

Best regards,
Whoopie


[-- Attachment #2: btsco-mutex.patch --]
[-- Type: text/x-patch, Size: 4484 bytes --]

--- btsco.c.orig	2006-03-31 14:37:18.000000000 +0200
+++ btsco.c	2006-03-31 14:41:10.000000000 +0200
@@ -65,6 +65,15 @@
 #define SNDRV_GET_ID
 #include <sound/initval.h>
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15)
+#include <linux/mutex.h>
+#else
+#define mutex semaphore
+#define mutex_init init_MUTEX
+#define mutex_lock down
+#define mutex_unlock up
+#endif
+
 #ifndef SNDRV_HWDEP_IFACE_BLUETOOTH
 #define SNDRV_HWDEP_IFACE_BLUETOOTH (SNDRV_HWDEP_IFACE_EMUX_WAVETABLE + 1)
 #endif
@@ -139,15 +148,15 @@
 	struct completion thread_done;
 
 	volatile int thread_exit;
-	struct semaphore thread_sem;
+	struct mutex thread_sem;
 
 	volatile struct socket *sco_sock;
-	struct semaphore sock_sem;
+	struct mutex sock_sem;
 	wait_queue_head_t wait;
 
-	struct semaphore playback_sem;
+	struct mutex playback_sem;
 	struct snd_card_bt_sco_pcm *playback;
-	struct semaphore capture_sem;
+	struct mutex capture_sem;
 	struct snd_card_bt_sco_pcm *capture;
 } snd_card_bt_sco_t;
 
@@ -435,8 +444,8 @@
 	    );
 
 	/* Ensure any references to this in our thread have finished */
-	down(&bt_sco->playback_sem);
-	up(&bt_sco->playback_sem);
+	mutex_lock(&bt_sco->playback_sem);
+	mutex_unlock(&bt_sco->playback_sem);
 
 	atomic_dec(&bt_sco->playback_count);
 	spin_lock_irq(&bt_sco->count_changed_lock);
@@ -458,8 +467,8 @@
 	    );
 
 	/* Ensure any references to this in our thread have finished */
-	down(&bt_sco->capture_sem);
-	up(&bt_sco->capture_sem);
+	mutex_lock(&bt_sco->capture_sem);
+	mutex_unlock(&bt_sco->capture_sem);
 
 	atomic_dec(&bt_sco->capture_count);
 	spin_lock_irq(&bt_sco->count_changed_lock);
@@ -700,7 +709,7 @@
 		err = 0;
 		/*  Interrupt any socket operations, so that we may
 		 *  change the socket */
-		down(&bt_sco->sock_sem);
+		mutex_lock(&bt_sco->sock_sem);
 		kill_proc(bt_sco->thread_pid, SIGINT, 1);
 		if (bt_sco->sco_sock) {
 			dprintk("Disposing of previous socket count %d\n",
@@ -729,7 +738,7 @@
 				}
 			}
 		}
-		up(&bt_sco->sock_sem);
+		mutex_unlock(&bt_sco->sock_sem);
 		break;
 	case SNDRV_BT_SCO_IOCTL_REQ_INFO:
 		spin_lock_irq(&bt_sco->count_changed_lock);
@@ -888,7 +897,7 @@
 	set_fs(KERNEL_DS);
 
 	dprintk("snd-bt-scod thread starting\n");
-	up(&bt_sco->thread_sem);
+	mutex_unlock(&bt_sco->thread_sem);
 
 	do {
 
@@ -912,11 +921,11 @@
 		if (bt_sco->thread_exit)
 			break;
 
-		down(&bt_sco->sock_sem);
+		mutex_lock(&bt_sco->sock_sem);
 		sock = (struct socket *)bt_sco->sco_sock;
 		if (sock)
 			get_file(sock->file);
-		up(&bt_sco->sock_sem);
+		mutex_unlock(&bt_sco->sock_sem);
 
 		if (!sock)
 			continue;
@@ -1011,14 +1020,14 @@
 			}
 #endif
 #endif /* any of them */
-			down(&bt_sco->capture_sem);
+			mutex_lock(&bt_sco->capture_sem);
 			if (bt_sco->capture) {
 				snd_card_bt_sco_pcm_receive
 				    (bt_sco->capture, buf, len);
 			}
-			up(&bt_sco->capture_sem);
+			mutex_unlock(&bt_sco->capture_sem);
 
-			down(&bt_sco->playback_sem);
+			mutex_lock(&bt_sco->playback_sem);
 
 			if (bt_sco->playback || !bt_sco->loopback) {
 				memset(buf, 0, len);
@@ -1055,7 +1064,7 @@
 					buf[notzero] = 0;
 				}
 			}
-			up(&bt_sco->playback_sem);
+			mutex_unlock(&bt_sco->playback_sem);
 
 #if 0
 			/* This chunk of code lets us record (using arecord)
@@ -1072,7 +1081,7 @@
 			   which is unsigned, whereas we are dealing with signed).
 			 */
 
-			down(&bt_sco->capture_sem);
+			mutex_lock(&bt_sco->capture_sem);
 			if (bt_sco->capture) {
 				snd_card_bt_sco_pcm_receive
 				    (bt_sco->capture, "\001\002\003\004", 4);
@@ -1081,7 +1090,7 @@
 				snd_card_bt_sco_pcm_receive
 				    (bt_sco->capture, "\004\003\002\001", 4);
 			}
-			up(&bt_sco->capture_sem);
+			mutex_unlock(&bt_sco->capture_sem);
 #endif
 			msg.msg_flags = 0;
 			msg.msg_iov = &iov;
@@ -1151,11 +1160,11 @@
 	bt_sco->card = card;
 
 	init_completion(&bt_sco->thread_done);
-	init_MUTEX(&bt_sco->thread_sem);
-	down(&bt_sco->thread_sem);
-	init_MUTEX(&bt_sco->sock_sem);
-	init_MUTEX(&bt_sco->capture_sem);
-	init_MUTEX(&bt_sco->playback_sem);
+	mutex_init(&bt_sco->thread_sem);
+	mutex_lock(&bt_sco->thread_sem);
+	mutex_init(&bt_sco->sock_sem);
+	mutex_init(&bt_sco->capture_sem);
+	mutex_init(&bt_sco->playback_sem);
 	init_waitqueue_head(&bt_sco->wait);
 	init_waitqueue_head(&bt_sco->hwdep_wait);
 	spin_lock_init(&bt_sco->mixer_changed_lock);
@@ -1170,7 +1179,7 @@
 		goto __nodev;
 	}
 
-	down(&bt_sco->thread_sem);
+	mutex_lock(&bt_sco->thread_sem);
 
 	if ((err = snd_card_bt_sco_pcm(bt_sco)) < 0)
 		goto __nodev;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-04-13 19:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-31 14:08 [Bluez-devel] [PATCH] snd-bt-sco and new mutex API in kernel 2.6.16 Whoopie
2006-04-13 19:50 ` Brad Midgley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).