PostgreSQL Source Code git master
Functions | Variables
test_dsa.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "storage/lwlock.h"
#include "utils/dsa.h"
#include "utils/resowner.h"
Include dependency graph for test_dsa.c:

Go to the source code of this file.

Functions

 
 
 
 

Variables

 

Function Documentation

PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( test_dsa_basic  )

PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( test_dsa_resowners  )

test_dsa_basic()

Datum test_dsa_basic ( PG_FUNCTION_ARGS  )

Definition at line 25 of file test_dsa.c.

26{
27 int tranche_id;
28 dsa_area *a;
29 dsa_pointer p[100];
30
31 /* XXX: this tranche is leaked */
32 tranche_id = LWLockNewTrancheId("test_dsa");
33
34 a = dsa_create(tranche_id);
35 for (int i = 0; i < 100; i++)
36 {
37 p[i] = dsa_allocate(a, 1000);
38 snprintf(dsa_get_address(a, p[i]), 1000, "foobar%d", i);
39 }
40
41 for (int i = 0; i < 100; i++)
42 {
43 char buf[100];
44
45 snprintf(buf, 100, "foobar%d", i);
46 if (strcmp(dsa_get_address(a, p[i]), buf) != 0)
47 elog(ERROR, "no match");
48 }
49
50 for (int i = 0; i < 100; i++)
51 {
52 dsa_free(a, p[i]);
53 }
54
56
58}
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
Definition: dsa.c:957
void dsa_detach(dsa_area *area)
Definition: dsa.c:1967
void dsa_free(dsa_area *area, dsa_pointer dp)
Definition: dsa.c:841
uint64 dsa_pointer
Definition: dsa.h:62
#define dsa_create(tranche_id)
Definition: dsa.h:117
#define dsa_allocate(area, size)
Definition: dsa.h:109
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define PG_RETURN_VOID()
Definition: fmgr.h:349
a
int a
Definition: isn.c:73
i
int i
Definition: isn.c:77
int LWLockNewTrancheId(const char *name)
Definition: lwlock.c:596
static char * buf
Definition: pg_test_fsync.c:72
#define snprintf
Definition: port.h:239
Definition: dsa.c:348

References a, buf, dsa_allocate, dsa_create, dsa_detach(), dsa_free(), dsa_get_address(), elog, ERROR, i, LWLockNewTrancheId(), PG_RETURN_VOID, and snprintf.

test_dsa_resowners()

Datum test_dsa_resowners ( PG_FUNCTION_ARGS  )

Definition at line 63 of file test_dsa.c.

64{
65 int tranche_id;
66 dsa_area *a;
67 dsa_pointer p[10000];
68 ResourceOwner oldowner;
69 ResourceOwner childowner;
70
71 /* XXX: this tranche is leaked */
72 tranche_id = LWLockNewTrancheId("test_dsa");
73
74 /* Create DSA in parent resource owner */
75 a = dsa_create(tranche_id);
76
77 /*
78 * Switch to child resource owner, and do a bunch of allocations in the
79 * DSA
80 */
81 oldowner = CurrentResourceOwner;
82 childowner = ResourceOwnerCreate(oldowner, "test_dsa temp owner");
83 CurrentResourceOwner = childowner;
84
85 for (int i = 0; i < 10000; i++)
86 {
87 p[i] = dsa_allocate(a, 1000);
88 snprintf(dsa_get_address(a, p[i]), 1000, "foobar%d", i);
89 }
90
91 /* Also test freeing, by freeing some of the allocations. */
92 for (int i = 0; i < 500; i++)
93 dsa_free(a, p[i]);
94
95 /* Release the child resource owner */
96 CurrentResourceOwner = oldowner;
97 ResourceOwnerRelease(childowner,
99 true, false);
100 ResourceOwnerRelease(childowner,
102 true, false);
103 ResourceOwnerRelease(childowner,
105 true, false);
106 ResourceOwnerDelete(childowner);
107
108 dsa_detach(a);
109
111}
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
Definition: resowner.c:418
ResourceOwner CurrentResourceOwner
Definition: resowner.c:173
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
Definition: resowner.c:655
void ResourceOwnerDelete(ResourceOwner owner)
Definition: resowner.c:868
@ RESOURCE_RELEASE_LOCKS
Definition: resowner.h:55
@ RESOURCE_RELEASE_BEFORE_LOCKS
Definition: resowner.h:54
@ RESOURCE_RELEASE_AFTER_LOCKS
Definition: resowner.h:56

References a, CurrentResourceOwner, dsa_allocate, dsa_create, dsa_detach(), dsa_free(), dsa_get_address(), i, LWLockNewTrancheId(), PG_RETURN_VOID, RESOURCE_RELEASE_AFTER_LOCKS, RESOURCE_RELEASE_BEFORE_LOCKS, RESOURCE_RELEASE_LOCKS, ResourceOwnerCreate(), ResourceOwnerDelete(), ResourceOwnerRelease(), and snprintf.

Variable Documentation

PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 20 of file test_dsa.c.

AltStyle によって変換されたページ (->オリジナル) /