base: genlock: allow synchronization with a single gralloc handle
In order to support synchronization in a process with a single
gralloc handle we require the ability to write lock a buffer
while it is already read locked by the same handle. This change
extends the concept of an exclusive write lock or recursive read
locks to a genlock handle (rather than the genlock lock).
Genlock cannot provide deadlock protection because the same
handle can be used simultaneously by a producer and consumer.
In practice an error will still be generated when the timeout
expires.
CRs-fixed: 356263
Change-Id: I322e7fadc8b43287f53b211242b176d3de731db2
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
diff --git a/include/linux/genlock.h b/include/linux/genlock.h
index 9351a15..60bc84c 100644
--- a/include/linux/genlock.h
+++ b/include/linux/genlock.h
@@ -1,6 +1,8 @@
#ifndef _GENLOCK_H_
#define _GENLOCK_H_
+#include <linux/bitops.h>
+
#ifdef __KERNEL__
struct genlock;
@@ -21,7 +23,8 @@
#define GENLOCK_WRLOCK 1
#define GENLOCK_RDLOCK 2
-#define GENLOCK_NOBLOCK (1 << 0)
+#define GENLOCK_NOBLOCK BIT(0)
+#define GENLOCK_WRITE_TO_READ BIT(1)
struct genlock_lock {
int fd;
@@ -37,6 +40,8 @@
struct genlock_lock)
#define GENLOCK_IOC_ATTACH _IOW(GENLOCK_IOC_MAGIC, 2, \
struct genlock_lock)
+
+/* Deprecated */
#define GENLOCK_IOC_LOCK _IOW(GENLOCK_IOC_MAGIC, 3, \
struct genlock_lock)
@@ -44,4 +49,6 @@
#define GENLOCK_IOC_RELEASE _IO(GENLOCK_IOC_MAGIC, 4)
#define GENLOCK_IOC_WAIT _IOW(GENLOCK_IOC_MAGIC, 5, \
struct genlock_lock)
+#define GENLOCK_IOC_DREADLOCK _IOW(GENLOCK_IOC_MAGIC, 6, \
+ struct genlock_lock)
#endif