From: Robert Haas Date: Thu, 21 Jan 2016 19:33:07 +0000 (-0500) Subject: test_group_deadlocks module from Amit X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=c52d778b4f65c76f7554e78ce336d970879d2198;p=users%2Frhaas%2Fpostgres.git test_group_deadlocks module from Amit --- diff --git a/contrib/Makefile b/contrib/Makefile index bd251f6c66..ff3c54d3c7 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -43,6 +43,7 @@ SUBDIRS = \ tablefunc \ tcn \ test_decoding \ + test_group_deadlocks \ tsm_system_rows \ tsm_system_time \ tsearch2 \ diff --git a/contrib/test_group_deadlocks/Makefile b/contrib/test_group_deadlocks/Makefile new file mode 100644 index 0000000000..057448c38a --- /dev/null +++ b/contrib/test_group_deadlocks/Makefile @@ -0,0 +1,19 @@ +# contrib/test_group_deadlocks/Makefile + +MODULE_big = test_group_deadlocks +OBJS = test_group_deadlocks.o $(WIN32RES) + +EXTENSION = test_group_deadlocks +DATA = test_group_deadlocks--1.0.sql +PGFILEDESC = "test_group_deadlocks - participate in group locking" + +ifdef USE_PGXS +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) +else +subdir = contrib/test_group_deadlocks +top_builddir = ../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/contrib/contrib-global.mk +endif diff --git a/contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql b/contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql new file mode 100644 index 0000000000..377c36319d --- /dev/null +++ b/contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql @@ -0,0 +1,15 @@ +/* contrib/test_group_deadlocks/test_group_deadlocks--1.0.sql */ + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION test_group_deadlocks" to load this file. \quit + +-- Register the function. +CREATE FUNCTION become_lock_group_leader() +RETURNS pg_catalog.void +AS 'MODULE_PATHNAME' +LANGUAGE C; + +CREATE FUNCTION become_lock_group_member(pid pg_catalog.int4) +RETURNS pg_catalog.bool +AS 'MODULE_PATHNAME' +LANGUAGE C; diff --git a/contrib/test_group_deadlocks/test_group_deadlocks.c b/contrib/test_group_deadlocks/test_group_deadlocks.c new file mode 100644 index 0000000000..f3d980ab15 --- /dev/null +++ b/contrib/test_group_deadlocks/test_group_deadlocks.c @@ -0,0 +1,57 @@ +/*------------------------------------------------------------------------- + * + * test_group_deadlocks.c + * group locking utilities + * + * Copyright (c) 2010-2014, PostgreSQL Global Development Group + * + * IDENTIFICATION + * contrib/test_group_deadlocks/test_group_deadlocks.c + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include "fmgr.h" +#include "storage/proc.h" +#include "storage/procarray.h" + +PG_MODULE_MAGIC; + +PG_FUNCTION_INFO_V1(become_lock_group_leader); +PG_FUNCTION_INFO_V1(become_lock_group_member); + + +/* + * become_lock_group_leader + * + * This function makes current backend process as lock group + * leader. + */ +Datum +become_lock_group_leader(PG_FUNCTION_ARGS) +{ + BecomeLockGroupLeader(); + + PG_RETURN_VOID(); +} + +/* + * become_lock_group_member + * + * This function makes current backend process as lock group + * member of the group owned by the process whose pid is passed + * as first argument. + */ +Datum +become_lock_group_member(PG_FUNCTION_ARGS) +{ + bool member; + PGPROC *procleader; + int32 pid = PG_GETARG_INT32(0); + + procleader = BackendPidGetProc(pid); + member = BecomeLockGroupMember(procleader, pid); + + PG_RETURN_BOOL(member); +} diff --git a/contrib/test_group_deadlocks/test_group_deadlocks.control b/contrib/test_group_deadlocks/test_group_deadlocks.control new file mode 100644 index 0000000000..e2dcc71b49 --- /dev/null +++ b/contrib/test_group_deadlocks/test_group_deadlocks.control @@ -0,0 +1,5 @@ +# test_group_locking extension +comment = 'become part of group' +default_version = '1.0' +module_pathname = '$libdir/test_group_deadlocks' +relocatable = true