File 00003-applock.patch of Package postgresql96

0535b07c46bd8189ca71b762e0d70206567a194a
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 387b5d6..af3df77 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -563,7 +563,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 
 /* ordinary key words in alphabetical order */
 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
-	AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
+	AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY APPLICATION ARRAY AS ASC
 	ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
 
 	BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
@@ -9801,6 +9801,8 @@ opt_lock:	IN_P lock_type MODE				{ $$ = $2; }
 lock_type:	ACCESS SHARE					{ $$ = AccessShareLock; }
 			| ROW SHARE						{ $$ = RowShareLock; }
 			| ROW EXCLUSIVE					{ $$ = RowExclusiveLock; }
+			| APPLICATION SHARE             { $$ = ApplicationShareLock; }
+			| APPLICATION EXCLUSIVE         { $$ = ApplicationExclusiveLock; }
 			| SHARE UPDATE EXCLUSIVE		{ $$ = ShareUpdateExclusiveLock; }
 			| SHARE							{ $$ = ShareLock; }
 			| SHARE ROW EXCLUSIVE			{ $$ = ShareRowExclusiveLock; }
@@ -13745,6 +13747,7 @@ unreserved_keyword:
 			| ALSO
 			| ALTER
 			| ALWAYS
+			| APPLICATION
 			| ASSERTION
 			| ASSIGNMENT
 			| AT
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index dba3809..0489679 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -100,8 +100,12 @@ static const LOCKMASK LockConflicts[] = {
 	LOCKBIT_ON(AccessShareLock) | LOCKBIT_ON(RowShareLock) |
 	LOCKBIT_ON(RowExclusiveLock) | LOCKBIT_ON(ShareUpdateExclusiveLock) |
 	LOCKBIT_ON(ShareLock) | LOCKBIT_ON(ShareRowExclusiveLock) |
-	LOCKBIT_ON(ExclusiveLock) | LOCKBIT_ON(AccessExclusiveLock)
+	LOCKBIT_ON(ExclusiveLock) | LOCKBIT_ON(AccessExclusiveLock),
 
+        /* ApplicationShareLock*/
+        LOCKBIT_ON(ApplicationExclusiveLock),
+        /* ApplicationExclusiveLock*/
+        LOCKBIT_ON(ApplicationExclusiveLock) | LOCKBIT_ON(ApplicationShareLock)
 };
 
 /* Names of lock modes, for debug printouts */
@@ -115,7 +119,9 @@ static const char *const lock_mode_names[] =
 	"ShareLock",
 	"ShareRowExclusiveLock",
 	"ExclusiveLock",
-	"AccessExclusiveLock"
+	"AccessExclusiveLock",
+    "ApplicationShareLock",
+    "ApplicationExclusiveLock"
 };
 
 #ifndef LOCK_DEBUG
@@ -123,7 +129,7 @@ static bool Dummy_trace = false;
 #endif
 
 static const LockMethodData default_lockmethod = {
-	AccessExclusiveLock,		/* highest valid lock mode number */
+	ApplicationExclusiveLock,		/* highest valid lock mode number */
 	LockConflicts,
 	lock_mode_names,
 #ifdef LOCK_DEBUG
@@ -134,7 +140,7 @@ static const LockMethodData default_lockmethod = {
 };
 
 static const LockMethodData user_lockmethod = {
-	AccessExclusiveLock,		/* highest valid lock mode number */
+	ApplicationExclusiveLock,		/* highest valid lock mode number */
 	LockConflicts,
 	lock_mode_names,
 #ifdef LOCK_DEBUG
diff --git a/src/include/parser/kwlist.h b/src/include/parser/kwlist.h
index 17ffef5..8366bba 100644
--- a/src/include/parser/kwlist.h
+++ b/src/include/parser/kwlist.h
@@ -42,6 +42,7 @@ PG_KEYWORD("analyse", ANALYSE, RESERVED_KEYWORD)		/* British spelling */
 PG_KEYWORD("analyze", ANALYZE, RESERVED_KEYWORD)
 PG_KEYWORD("and", AND, RESERVED_KEYWORD)
 PG_KEYWORD("any", ANY, RESERVED_KEYWORD)
+PG_KEYWORD("application", APPLICATION, UNRESERVED_KEYWORD)
 PG_KEYWORD("array", ARRAY, RESERVED_KEYWORD)
 PG_KEYWORD("as", AS, RESERVED_KEYWORD)
 PG_KEYWORD("asc", ASC, RESERVED_KEYWORD)
diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h
index efa75ec..df25212 100644
--- a/src/include/storage/lock.h
+++ b/src/include/storage/lock.h
@@ -83,7 +83,7 @@ typedef struct
 	 (vxid).localTransactionId = (proc).lxid)
 
 /* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */
-#define MAX_LOCKMODES		10
+#define MAX_LOCKMODES		12
 
 #define LOCKBIT_ON(lockmode) (1 << (lockmode))
 #define LOCKBIT_OFF(lockmode) (~(1 << (lockmode)))
diff --git a/src/include/storage/lockdefs.h b/src/include/storage/lockdefs.h
index dd7cb16..d707c5e 100644
--- a/src/include/storage/lockdefs.h
+++ b/src/include/storage/lockdefs.h
@@ -45,6 +45,8 @@ typedef int LOCKMODE;
 										 * UPDATE */
 #define AccessExclusiveLock		8		/* ALTER TABLE, DROP TABLE, VACUUM
 										 * FULL, and unqualified LOCK TABLE */
+#define ApplicationShareLock       9   /* requested explicitly */
+#define ApplicationExclusiveLock   10  /* requested explicitly */
 
 typedef struct xl_standby_lock
 {
diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y
index 13fa52d..6959c98 100644
--- a/src/interfaces/ecpg/preproc/preproc.y
+++ b/src/interfaces/ecpg/preproc/preproc.y
@@ -1391,7 +1391,7 @@ add_typedef(char *name, char *dimension, char *length, enum ECPGttype type_enum,
 
 
  %token ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
- AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
+ AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY APPLICATION ARRAY AS ASC
  ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
 
  BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
@@ -8898,6 +8898,14 @@ RETURNING target_list ecpg_into
  { 
  $$ = mm_strdup("row exclusive");
 }
+|  APPLICATION SHARE
+ { 
+ $$ = mm_strdup("application share");
+}
+|  APPLICATION EXCLUSIVE
+ { 
+ $$ = mm_strdup("application exclusive");
+}
 |  SHARE UPDATE EXCLUSIVE
  { 
  $$ = mm_strdup("share update exclusive");
@@ -12316,6 +12324,10 @@ mmerror(PARSE_ERROR, ET_WARNING, "unsupported feature will be passed to server")
  { 
  $$ = mm_strdup("always");
 }
+|  APPLICATION
+ { 
+ $$ = mm_strdup("application");
+}
 |  ASSERTION
  { 
  $$ = mm_strdup("assertion");