PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_lwlock_tranches.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "storage/lwlock.h"
#include "utils/builtins.h"
#include "utils/wait_classes.h"
Include dependency graph for test_lwlock_tranches.c:

Go to the source code of this file.

Functions

static void test_lwlock_tranches_shmem_request (void)
 
void _PG_init (void)
 
 PG_FUNCTION_INFO_V1 (test_startup_lwlocks)
 
Datum test_startup_lwlocks (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_lwlock_tranche_create)
 
Datum test_lwlock_tranche_create (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_lwlock_tranche_lookup)
 
Datum test_lwlock_tranche_lookup (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_lwlock_get_lwlock_identifier)
 
Datum test_lwlock_get_lwlock_identifier (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_lwlock_initialize)
 
Datum test_lwlock_initialize (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static shmem_request_hook_type prev_shmem_request_hook
 

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 28 of file test_lwlock_tranches.c.

29{
32}
shmem_request_hook_type shmem_request_hook
Definition miscinit.c:1791
static shmem_request_hook_type prev_shmem_request_hook
static void test_lwlock_tranches_shmem_request(void)

References prev_shmem_request_hook, shmem_request_hook, and test_lwlock_tranches_shmem_request().

◆ PG_FUNCTION_INFO_V1() [1/5]

PG_FUNCTION_INFO_V1 ( test_lwlock_get_lwlock_identifier  )

◆ PG_FUNCTION_INFO_V1() [2/5]

PG_FUNCTION_INFO_V1 ( test_lwlock_initialize  )

◆ PG_FUNCTION_INFO_V1() [3/5]

PG_FUNCTION_INFO_V1 ( test_lwlock_tranche_create  )

◆ PG_FUNCTION_INFO_V1() [4/5]

PG_FUNCTION_INFO_V1 ( test_lwlock_tranche_lookup  )

◆ PG_FUNCTION_INFO_V1() [5/5]

PG_FUNCTION_INFO_V1 ( test_startup_lwlocks  )

◆ test_lwlock_get_lwlock_identifier()

Datum test_lwlock_get_lwlock_identifier ( PG_FUNCTION_ARGS  )

Definition at line 115 of file test_lwlock_tranches.c.

116{
117 int eventId = PG_GETARG_INT32(0);
118 const char *tranche_name;
119
121
122 if (tranche_name)
123 PG_RETURN_TEXT_P(cstring_to_text(tranche_name));
124 else
126}
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
const char * GetLWLockIdentifier(uint32 classId, uint16 eventId)
Definition lwlock.c:747
static int fb(int x)
text * cstring_to_text(const char *s)
Definition varlena.c:184
#define PG_WAIT_LWLOCK

References cstring_to_text(), fb(), GetLWLockIdentifier(), PG_GETARG_INT32, PG_RETURN_NULL, PG_RETURN_TEXT_P, and PG_WAIT_LWLOCK.

◆ test_lwlock_initialize()

Datum test_lwlock_initialize ( PG_FUNCTION_ARGS  )

Definition at line 133 of file test_lwlock_tranches.c.

134{
135 int tranche_id = PG_GETARG_INT32(0);
136 LWLock lock;
137
138 LWLockInitialize(&lock, tranche_id);
139
141}
#define PG_RETURN_VOID()
Definition fmgr.h:350
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition lwlock.c:670

References LWLockInitialize(), PG_GETARG_INT32, and PG_RETURN_VOID.

◆ test_lwlock_tranche_create()

Datum test_lwlock_tranche_create ( PG_FUNCTION_ARGS  )

Definition at line 89 of file test_lwlock_tranches.c.

90{
91 char *tranche_name = PG_ARGISNULL(0) ? NULL : TextDatumGetCString(PG_GETARG_DATUM(0));
92 int tranche_id;
93
94 tranche_id = LWLockNewTrancheId(tranche_name);
95
96 PG_RETURN_INT32(tranche_id);
97}
#define TextDatumGetCString(d)
Definition builtins.h:99
#define PG_ARGISNULL(n)
Definition fmgr.h:209
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
int LWLockNewTrancheId(const char *name)
Definition lwlock.c:562

References fb(), LWLockNewTrancheId(), PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_INT32, and TextDatumGetCString.

◆ test_lwlock_tranche_lookup()

Datum test_lwlock_tranche_lookup ( PG_FUNCTION_ARGS  )

Definition at line 104 of file test_lwlock_tranches.c.

105{
106 char *tranche_name = TextDatumGetCString(PG_GETARG_DATUM(0));
107
108 (void) GetNamedLWLockTranche(tranche_name);
109
111}
LWLockPadded * GetNamedLWLockTranche(const char *tranche_name)
Definition lwlock.c:522

References fb(), GetNamedLWLockTranche(), PG_GETARG_DATUM, PG_RETURN_VOID, and TextDatumGetCString.

◆ test_lwlock_tranches_shmem_request()

static void test_lwlock_tranches_shmem_request ( void  )
static

Definition at line 35 of file test_lwlock_tranches.c.

36{
39
40 /*
41 * Request some tranches with RequestNamedLWLockTranche() for
42 * test_startup_lwlocks()
43 */
44 RequestNamedLWLockTranche("test_lwlock_tranches_startup", 1);
45 RequestNamedLWLockTranche("test_lwlock_tranches_startup10", 10);
46}
void RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
Definition lwlock.c:620

References prev_shmem_request_hook, and RequestNamedLWLockTranche().

Referenced by _PG_init().

◆ test_startup_lwlocks()

Datum test_startup_lwlocks ( PG_FUNCTION_ARGS  )

Definition at line 53 of file test_lwlock_tranches.c.

54{
57
58 /* Check that the locks can be used */
59 lwlock_startup = GetNamedLWLockTranche("test_lwlock_tranches_startup");
60 lwlock_startup10 = GetNamedLWLockTranche("test_lwlock_tranches_startup10");
61
63 for (int i = 0; i < 10; i++)
65
67 for (int i = 0; i < 10; i++)
69
70 /*
71 * Check that GetLWLockIdentifier() returns the expected value for
72 * tranches
73 */
74 if (strcmp("test_lwlock_tranches_startup",
76 elog(ERROR, "incorrect startup lock tranche name");
77 if (strcmp("test_lwlock_tranches_startup10",
79 elog(ERROR, "incorrect startup lock tranche name");
80
82}
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
int i
Definition isn.c:77
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LWTRANCHE_FIRST_USER_DEFINED
Definition lwlock.h:172
@ LW_EXCLUSIVE
Definition lwlock.h:104

References elog, ERROR, fb(), GetLWLockIdentifier(), GetNamedLWLockTranche(), i, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), LWTRANCHE_FIRST_USER_DEFINED, PG_RETURN_VOID, and PG_WAIT_LWLOCK.

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 22 of file test_lwlock_tranches.c.

◆ prev_shmem_request_hook

shmem_request_hook_type prev_shmem_request_hook
static

Definition at line 24 of file test_lwlock_tranches.c.

Referenced by _PG_init(), and test_lwlock_tranches_shmem_request().