Diff between 9ce8d3f01e2ae179125ddf92b56214430fd23ef3 and 06eb47dec55e8bc53ccceffad3823320f47f7cb0

Changed Files

File Additions Deletions Status
audio/gateway.c +38 -0 modified
audio/gateway.h +8 -0 modified

Full Patch

diff --git a/audio/gateway.c b/audio/gateway.c
index c3c4019..142b12e 100644
--- a/audio/gateway.c
+++ b/audio/gateway.c
@@ -70,6 +70,7 @@ struct gateway {
 	struct hf_agent *agent;
 	DBusMessage *msg;
 	int version;
+	gateway_lock_t lock;
 };
 
 struct gateway_state_callback {
@@ -873,3 +874,40 @@ gboolean gateway_remove_state_cb(unsigned int id)
 
 	return FALSE;
 }
+
+gateway_lock_t gateway_get_lock(struct audio_device *dev)
+{
+	struct gateway *gw = dev->gateway;
+
+	return gw->lock;
+}
+
+gboolean gateway_lock(struct audio_device *dev, gateway_lock_t lock)
+{
+	struct gateway *gw = dev->gateway;
+
+	if (gw->lock & lock)
+		return FALSE;
+
+	gw->lock |= lock;
+
+	return TRUE;
+}
+
+gboolean gateway_unlock(struct audio_device *dev, gateway_lock_t lock)
+{
+	struct gateway *gw = dev->gateway;
+
+	if (!(gw->lock & lock))
+		return FALSE;
+
+	gw->lock &= ~lock;
+
+	if (gw->lock)
+		return TRUE;
+
+	if (gw->state == GATEWAY_STATE_PLAYING)
+		gateway_suspend_stream(dev);
+
+	return TRUE;
+}
diff --git a/audio/gateway.h b/audio/gateway.h
index 32b5d6d..2dca32a 100644
--- a/audio/gateway.h
+++ b/audio/gateway.h
@@ -33,6 +33,11 @@ typedef enum {
 	GATEWAY_STATE_PLAYING,
 } gateway_state_t;
 
+typedef enum {
+	GATEWAY_LOCK_READ = 1,
+	GATEWAY_LOCK_WRITE = 1 << 1,
+} gateway_lock_t;
+
 typedef void (*gateway_state_cb) (struct audio_device *dev,
 					gateway_state_t old_state,
 					gateway_state_t new_state,
@@ -56,3 +61,6 @@ int gateway_get_sco_fd(struct audio_device *dev);
 void gateway_suspend_stream(struct audio_device *dev);
 unsigned int gateway_add_state_cb(gateway_state_cb cb, void *user_data);
 gboolean gateway_remove_state_cb(unsigned int id);
+gateway_lock_t gateway_get_lock(struct audio_device *dev);
+gboolean gateway_lock(struct audio_device *dev, gateway_lock_t lock);
+gboolean gateway_unlock(struct audio_device *dev, gateway_lock_t lock);