Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f78aa5

Browse files
committed
Shared Memory Hooks Documentation
This patch, against xfunc.sgml, adds a new subsection 33.9.12, SharedMemory and LWLocks in C-Language Functions, describing how shared memoryand lwlocks may be requested by C add-in functions.Marc Munro
1 parent3e0c96b commit5f78aa5

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

‎doc/src/sgml/xfunc.sgml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.117 2006/09/16 00:30:16 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.118 2006/11/23 03:52:05 momjian Exp $ -->
22

33
<sect1 id="xfunc">
44
<title>User-Defined Functions</title>
@@ -2906,6 +2906,54 @@ make_array(PG_FUNCTION_ARGS)
29062906
CREATE FUNCTION make_array(anyelement) RETURNS anyarray
29072907
AS '<replaceable>DIRECTORY</replaceable>/funcs', 'make_array'
29082908
LANGUAGE C IMMUTABLE;
2909+
</programlisting>
2910+
</para>
2911+
</sect2>
2912+
<sect2>
2913+
<title>Shared Memory and LWLocks in C-Language Functions</title>
2914+
2915+
<para>
2916+
Add-ins may reserve LWLocks and an allocation of shared memory on server
2917+
startup. The add-in's shared library must be preloaded, by specifying
2918+
it in
2919+
<xref linkend="guc-shared-preload-libraries"><indexterm><primary>shared-preload-libraries</></>,
2920+
and the shared memory must be reserved by calling:
2921+
<programlisting>
2922+
void RequestAddinShmemSpace(int size)
2923+
</programlisting>
2924+
from your <literal>_PG_init</> function.
2925+
</para>
2926+
<para>
2927+
LWLocks are reserved by calling:
2928+
<programlisting>
2929+
void RequestAddinLWLocks(int n)
2930+
</programlisting>
2931+
from <literal>_PG_init</>.
2932+
</para>
2933+
<para>
2934+
To avoid possible race-conditions, each backend should use the LWLock
2935+
<literal>AddinShmemInitLock</> when connecting to and intializing
2936+
its allocation of shared memory, as shown here:
2937+
2938+
<programlisting>
2939+
static mystruct *ptr = NULL;
2940+
2941+
if (!ptr)
2942+
{
2943+
bool found;
2944+
2945+
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
2946+
ptr = ShmemInitStruct("my struct name", size, &amp;found);
2947+
if (!ptr)
2948+
elog(ERROR, "out of shared memory");
2949+
if (!found)
2950+
{
2951+
initialize contents of shmem area;
2952+
acquire any requested LWLocks using:
2953+
ptr->mylockid = LWLockAssign();
2954+
}
2955+
LWLockRelease(AddinShmemInitLock);
2956+
}
29092957
</programlisting>
29102958
</para>
29112959
</sect2>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp