PostgreSQL Source Code git master
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.

Macros

#define STARTUP_TRANCHE_NAME   "test_lwlock_tranches_startup"
 
#define DYNAMIC_TRANCHE_NAME   "test_lwlock_tranches_dynamic"
 
#define NUM_STARTUP_TRANCHES   (32)
 
#define NUM_DYNAMIC_TRANCHES   (256 - NUM_STARTUP_TRANCHES)
 
#define GET_TRANCHE_NAME(a)   GetLWLockIdentifier(PG_WAIT_LWLOCK, (a))
 

Functions

static void test_lwlock_tranches_shmem_request (void)
 
void _PG_init (void)
 
 PG_FUNCTION_INFO_V1 (test_lwlock_tranches)
 
Datum test_lwlock_tranches (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (test_lwlock_tranche_creation)
 
Datum test_lwlock_tranche_creation (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_initialize)
 
Datum test_lwlock_initialize (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static shmem_request_hook_type prev_shmem_request_hook
 

Macro Definition Documentation

◆ DYNAMIC_TRANCHE_NAME

#define DYNAMIC_TRANCHE_NAME   "test_lwlock_tranches_dynamic"

Definition at line 25 of file test_lwlock_tranches.c.

◆ GET_TRANCHE_NAME

#define GET_TRANCHE_NAME (   a)    GetLWLockIdentifier(PG_WAIT_LWLOCK, (a))

Definition at line 30 of file test_lwlock_tranches.c.

◆ NUM_DYNAMIC_TRANCHES

#define NUM_DYNAMIC_TRANCHES   (256 - NUM_STARTUP_TRANCHES)

Definition at line 28 of file test_lwlock_tranches.c.

◆ NUM_STARTUP_TRANCHES

#define NUM_STARTUP_TRANCHES   (32)

Definition at line 27 of file test_lwlock_tranches.c.

◆ STARTUP_TRANCHE_NAME

#define STARTUP_TRANCHE_NAME   "test_lwlock_tranches_startup"

Definition at line 24 of file test_lwlock_tranches.c.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 36 of file test_lwlock_tranches.c.

37{
40}
shmem_request_hook_type shmem_request_hook
Definition: miscinit.c:1789
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/4]

PG_FUNCTION_INFO_V1 ( test_lwlock_initialize  )

◆ PG_FUNCTION_INFO_V1() [2/4]

PG_FUNCTION_INFO_V1 ( test_lwlock_tranche_creation  )

◆ PG_FUNCTION_INFO_V1() [3/4]

PG_FUNCTION_INFO_V1 ( test_lwlock_tranche_lookup  )

◆ PG_FUNCTION_INFO_V1() [4/4]

PG_FUNCTION_INFO_V1 ( test_lwlock_tranches  )

◆ test_lwlock_initialize()

Datum test_lwlock_initialize ( PG_FUNCTION_ARGS  )

Definition at line 115 of file test_lwlock_tranches.c.

116{
117 int tranche_id = PG_GETARG_INT32(0);
118 LWLock lock;
119
120 LWLockInitialize(&lock, tranche_id);
121
123}
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:698
Definition: lwlock.h:42

References LWLockInitialize(), PG_GETARG_INT32, and PG_RETURN_VOID.

◆ test_lwlock_tranche_creation()

Datum test_lwlock_tranche_creation ( PG_FUNCTION_ARGS  )

Definition at line 87 of file test_lwlock_tranches.c.

88{
89 char *tranche_name = PG_ARGISNULL(0) ? NULL : TextDatumGetCString(PG_GETARG_DATUM(0));
90
91 (void) LWLockNewTrancheId(tranche_name);
92
94}
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
int LWLockNewTrancheId(const char *name)
Definition: lwlock.c:596

References LWLockNewTrancheId(), PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_VOID, and TextDatumGetCString.

◆ test_lwlock_tranche_lookup()

Datum test_lwlock_tranche_lookup ( PG_FUNCTION_ARGS  )

Definition at line 101 of file test_lwlock_tranches.c.

102{
103 char *tranche_name = TextDatumGetCString(PG_GETARG_DATUM(0));
104
105 (void) GetNamedLWLockTranche(tranche_name);
106
108}
LWLockPadded * GetNamedLWLockTranche(const char *tranche_name)
Definition: lwlock.c:566

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

◆ test_lwlock_tranches()

Datum test_lwlock_tranches ( PG_FUNCTION_ARGS  )

Definition at line 58 of file test_lwlock_tranches.c.

59{
60 int dynamic_tranches[NUM_DYNAMIC_TRANCHES];
61
62 for (int i = 0; i < NUM_DYNAMIC_TRANCHES; i++)
63 dynamic_tranches[i] = LWLockNewTrancheId(DYNAMIC_TRANCHE_NAME);
64
65 for (int i = 0; i < NUM_STARTUP_TRANCHES; i++)
66 {
69 elog(ERROR, "incorrect startup lock tranche name");
70 }
71
72 for (int i = 0; i < NUM_DYNAMIC_TRANCHES; i++)
73 {
74 if (strcmp(GET_TRANCHE_NAME(dynamic_tranches[i]),
76 elog(ERROR, "incorrect dynamic lock tranche name");
77 }
78
80}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
int i
Definition: isn.c:77
@ LWTRANCHE_FIRST_USER_DEFINED
Definition: lwlock.h:186
#define STARTUP_TRANCHE_NAME
#define NUM_STARTUP_TRANCHES
#define GET_TRANCHE_NAME(a)
#define NUM_DYNAMIC_TRANCHES
#define DYNAMIC_TRANCHE_NAME

References DYNAMIC_TRANCHE_NAME, elog, ERROR, GET_TRANCHE_NAME, i, LWLockNewTrancheId(), LWTRANCHE_FIRST_USER_DEFINED, NUM_DYNAMIC_TRANCHES, NUM_STARTUP_TRANCHES, PG_RETURN_VOID, and STARTUP_TRANCHE_NAME.

◆ test_lwlock_tranches_shmem_request()

static void test_lwlock_tranches_shmem_request ( void  )
static

Definition at line 43 of file test_lwlock_tranches.c.

44{
47
48 for (int i = 0; i < NUM_STARTUP_TRANCHES; i++)
50}
void RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
Definition: lwlock.c:649

References i, NUM_STARTUP_TRANCHES, prev_shmem_request_hook, RequestNamedLWLockTranche(), and STARTUP_TRANCHE_NAME.

Referenced by _PG_init().

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 32 of file test_lwlock_tranches.c.

Referenced by _PG_init(), and test_lwlock_tranches_shmem_request().