mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 05:56:21 +00:00
Fixing code indentation with pgindent
This commit is contained in:
committed by
Muhammad Usama
parent
1883b05fc7
commit
faa938b8f1
462
hash_query.c
462
hash_query.c
@@ -18,18 +18,18 @@
|
||||
#include "nodes/pg_list.h"
|
||||
#include "pg_stat_monitor.h"
|
||||
|
||||
static pgsmLocalState pgsmStateLocal;
|
||||
static PGSM_HASH_TABLE_HANDLE pgsm_create_bucket_hash(pgsmSharedState *pgsm, dsa_area *dsa);
|
||||
static pgsmLocalState pgsmStateLocal;
|
||||
static PGSM_HASH_TABLE_HANDLE pgsm_create_bucket_hash(pgsmSharedState * pgsm, dsa_area * dsa);
|
||||
static Size pgsm_get_shared_area_size(void);
|
||||
static void InitializeSharedState(pgsmSharedState *pgsm);
|
||||
static void InitializeSharedState(pgsmSharedState * pgsm);
|
||||
|
||||
#if USE_DYNAMIC_HASH
|
||||
/* parameter for the shared hash */
|
||||
static dshash_parameters dsh_params = {
|
||||
sizeof(pgsmHashKey),
|
||||
sizeof(pgsmEntry),
|
||||
dshash_memcmp,
|
||||
dshash_memhash
|
||||
sizeof(pgsmHashKey),
|
||||
sizeof(pgsmEntry),
|
||||
dshash_memcmp,
|
||||
dshash_memhash
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -40,28 +40,26 @@ static dshash_parameters dsh_params = {
|
||||
*/
|
||||
|
||||
static Size
|
||||
pgsm_query_area_size(void)
|
||||
{
|
||||
Size sz = MAX_QUERY_BUF;
|
||||
#if USE_DYNAMIC_HASH
|
||||
/* Dynamic hash also lives DSA area */
|
||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||
#endif
|
||||
return MAXALIGN(sz);
|
||||
pgsm_query_area_size(void) {
|
||||
Size sz = MAX_QUERY_BUF;
|
||||
#if USE_DYNAMIC_HASH
|
||||
/* Dynamic hash also lives DSA area */
|
||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||
#endif
|
||||
return MAXALIGN(sz);
|
||||
}
|
||||
/*
|
||||
* Total shared memory area required by pgsm
|
||||
*/
|
||||
Size
|
||||
pgsm_ShmemSize(void)
|
||||
{
|
||||
pgsm_ShmemSize(void) {
|
||||
Size sz = MAXALIGN(sizeof(pgsmSharedState));
|
||||
sz = add_size(sz, MAX_QUERY_BUF);
|
||||
#if USE_DYNAMIC_HASH
|
||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||
#else
|
||||
sz = add_size(sz, hash_estimate_size(MAX_BUCKET_ENTRIES, sizeof(pgsmEntry)));
|
||||
#endif
|
||||
#if USE_DYNAMIC_HASH
|
||||
sz = add_size(sz, MAX_BUCKETS_MEM);
|
||||
#else
|
||||
sz = add_size(sz, hash_estimate_size(MAX_BUCKET_ENTRIES, sizeof(pgsmEntry)));
|
||||
#endif
|
||||
return MAXALIGN(sz);
|
||||
}
|
||||
|
||||
@@ -72,91 +70,90 @@ pgsm_ShmemSize(void)
|
||||
* get allocated as a single shared memory chunk.
|
||||
*/
|
||||
static Size
|
||||
pgsm_get_shared_area_size(void)
|
||||
{
|
||||
Size sz;
|
||||
#if USE_DYNAMIC_HASH
|
||||
sz = pgsm_ShmemSize();
|
||||
#else
|
||||
sz = MAXALIGN(sizeof(pgsmSharedState));
|
||||
sz = add_size(sz, pgsm_query_area_size());
|
||||
#endif
|
||||
return sz;
|
||||
pgsm_get_shared_area_size(void) {
|
||||
Size sz;
|
||||
#if USE_DYNAMIC_HASH
|
||||
sz = pgsm_ShmemSize();
|
||||
#else
|
||||
sz = MAXALIGN(sizeof(pgsmSharedState));
|
||||
sz = add_size(sz, pgsm_query_area_size());
|
||||
#endif
|
||||
return sz;
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_startup(void)
|
||||
{
|
||||
bool found = false;
|
||||
pgsmSharedState *pgsm;
|
||||
/* reset in case this is a restart within the postmaster */
|
||||
pgsmStateLocal.dsa = NULL;
|
||||
pgsmStateLocal.shared_hash = NULL;
|
||||
pgsmStateLocal.shared_pgsmState = NULL;
|
||||
bool found = false;
|
||||
pgsmSharedState *pgsm;
|
||||
/* reset in case this is a restart within the postmaster */
|
||||
pgsmStateLocal.dsa = NULL;
|
||||
pgsmStateLocal.shared_hash = NULL;
|
||||
pgsmStateLocal.shared_pgsmState = NULL;
|
||||
|
||||
/*
|
||||
* Create or attach to the shared memory state, including hash table
|
||||
*/
|
||||
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
|
||||
|
||||
pgsm = ShmemInitStruct("pg_stat_monitor", pgsm_get_shared_area_size(), &found);
|
||||
if (!found) {
|
||||
/* First time through ... */
|
||||
dsa_area *dsa;
|
||||
char *p = (char *) pgsm;
|
||||
|
||||
pgsm->pgsm_oom = false;
|
||||
pgsm->lock = &(GetNamedLWLockTranche("pg_stat_monitor"))->lock;
|
||||
SpinLockInit(&pgsm->mutex);
|
||||
InitializeSharedState(pgsm);
|
||||
/* the allocation of pgsmSharedState itself */
|
||||
p += MAXALIGN(sizeof(pgsmSharedState));
|
||||
pgsm->raw_dsa_area = p;
|
||||
dsa = dsa_create_in_place(pgsm->raw_dsa_area,
|
||||
pgsm_query_area_size(),
|
||||
LWLockNewTrancheId(), 0);
|
||||
dsa_pin(dsa);
|
||||
dsa_set_size_limit(dsa, pgsm_query_area_size());
|
||||
|
||||
pgsm->hash_handle = pgsm_create_bucket_hash(pgsm, dsa);
|
||||
|
||||
/*
|
||||
* Create or attach to the shared memory state, including hash table
|
||||
* If overflow is enabled, set the DSA size to unlimited, and allow
|
||||
* the DSA to grow beyond the shared memory space into the swap area
|
||||
*/
|
||||
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
|
||||
if (pgsm_enable_overflow)
|
||||
dsa_set_size_limit(dsa, -1);
|
||||
|
||||
pgsm = ShmemInitStruct("pg_stat_monitor", pgsm_get_shared_area_size(), &found);
|
||||
if (!found)
|
||||
{
|
||||
/* First time through ... */
|
||||
dsa_area *dsa;
|
||||
char *p = (char *) pgsm;
|
||||
|
||||
pgsm->pgsm_oom = false;
|
||||
pgsm->lock = &(GetNamedLWLockTranche("pg_stat_monitor"))->lock;
|
||||
SpinLockInit(&pgsm->mutex);
|
||||
InitializeSharedState(pgsm);
|
||||
/* the allocation of pgsmSharedState itself */
|
||||
p += MAXALIGN(sizeof(pgsmSharedState));
|
||||
pgsm->raw_dsa_area = p;
|
||||
dsa = dsa_create_in_place(pgsm->raw_dsa_area,
|
||||
pgsm_query_area_size(),
|
||||
LWLockNewTrancheId(), 0);
|
||||
dsa_pin(dsa);
|
||||
dsa_set_size_limit(dsa, pgsm_query_area_size());
|
||||
|
||||
pgsm->hash_handle = pgsm_create_bucket_hash(pgsm,dsa);
|
||||
|
||||
/* If overflow is enabled, set the DSA size to unlimited,
|
||||
* and allow the DSA to grow beyond the shared memory space
|
||||
* into the swap area*/
|
||||
if (pgsm_enable_overflow)
|
||||
dsa_set_size_limit(dsa, -1);
|
||||
|
||||
pgsmStateLocal.shared_pgsmState = pgsm;
|
||||
/*
|
||||
* Postmaster will never access the dsa again, thus free it's local
|
||||
* references.
|
||||
*/
|
||||
dsa_detach(dsa);
|
||||
}
|
||||
pgsmStateLocal.shared_pgsmState = pgsm;
|
||||
/*
|
||||
* Postmaster will never access the dsa again, thus free it's local
|
||||
* references.
|
||||
*/
|
||||
dsa_detach(dsa);
|
||||
}
|
||||
|
||||
#ifdef BENCHMARK
|
||||
init_hook_stats();
|
||||
init_hook_stats();
|
||||
#endif
|
||||
|
||||
LWLockRelease(AddinShmemInitLock);
|
||||
LWLockRelease(AddinShmemInitLock);
|
||||
|
||||
/*
|
||||
* If we're in the postmaster (or a standalone backend...), set up a shmem
|
||||
* exit hook to dump the statistics to disk.
|
||||
*/
|
||||
on_shmem_exit(pgsm_shmem_shutdown, (Datum) 0);
|
||||
/*
|
||||
* If we're in the postmaster (or a standalone backend...), set up a shmem
|
||||
* exit hook to dump the statistics to disk.
|
||||
*/
|
||||
on_shmem_exit(pgsm_shmem_shutdown, (Datum) 0);
|
||||
}
|
||||
|
||||
static void
|
||||
InitializeSharedState(pgsmSharedState *pgsm)
|
||||
InitializeSharedState(pgsmSharedState * pgsm)
|
||||
{
|
||||
pg_atomic_init_u64(&pgsm->current_wbucket, 0);
|
||||
pg_atomic_init_u64(&pgsm->prev_bucket_sec, 0);
|
||||
memset(&pgsm->bucket_entry, 0, MAX_BUCKETS * sizeof(uint64));
|
||||
pgsm->pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
|
||||
"pg_stat_monitor local store",
|
||||
ALLOCSET_DEFAULT_SIZES);
|
||||
pg_atomic_init_u64(&pgsm->current_wbucket, 0);
|
||||
pg_atomic_init_u64(&pgsm->prev_bucket_sec, 0);
|
||||
memset(&pgsm->bucket_entry, 0, MAX_BUCKETS * sizeof(uint64));
|
||||
pgsm->pgsm_mem_cxt = AllocSetContextCreate(TopMemoryContext,
|
||||
"pg_stat_monitor local store",
|
||||
ALLOCSET_DEFAULT_SIZES);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,29 +161,28 @@ InitializeSharedState(pgsmSharedState *pgsm)
|
||||
* Create the classic or dshahs hash table for storing the query statistics.
|
||||
*/
|
||||
static PGSM_HASH_TABLE_HANDLE
|
||||
pgsm_create_bucket_hash(pgsmSharedState *pgsm, dsa_area *dsa)
|
||||
{
|
||||
PGSM_HASH_TABLE_HANDLE bucket_hash;
|
||||
pgsm_create_bucket_hash(pgsmSharedState * pgsm, dsa_area * dsa) {
|
||||
PGSM_HASH_TABLE_HANDLE bucket_hash;
|
||||
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_table *dsh;
|
||||
pgsm->hash_tranche_id = LWLockNewTrancheId();
|
||||
dsh_params.tranche_id = pgsm->hash_tranche_id;
|
||||
dsh = dshash_create(dsa, &dsh_params, 0);
|
||||
bucket_hash = dshash_get_hash_table_handle(dsh);
|
||||
dshash_detach(dsh);
|
||||
dshash_table *dsh;
|
||||
pgsm->hash_tranche_id = LWLockNewTrancheId();
|
||||
dsh_params.tranche_id = pgsm->hash_tranche_id;
|
||||
dsh = dshash_create(dsa, &dsh_params, 0);
|
||||
bucket_hash = dshash_get_hash_table_handle(dsh);
|
||||
dshash_detach(dsh);
|
||||
#else
|
||||
HASHCTL info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.keysize = sizeof(pgsmHashKey);
|
||||
info.entrysize = sizeof(pgsmEntry);
|
||||
bucket_hash = ShmemInitHash("pg_stat_monitor: bucket hashtable", MAX_BUCKET_ENTRIES, MAX_BUCKET_ENTRIES, &info, HASH_ELEM | HASH_BLOBS);
|
||||
HASHCTL info;
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.keysize = sizeof(pgsmHashKey);
|
||||
info.entrysize = sizeof(pgsmEntry);
|
||||
bucket_hash = ShmemInitHash("pg_stat_monitor: bucket hashtable", MAX_BUCKET_ENTRIES, MAX_BUCKET_ENTRIES, &info, HASH_ELEM | HASH_BLOBS);
|
||||
#endif
|
||||
return bucket_hash;
|
||||
return bucket_hash;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attach to a DSA area created by the postmaster, in the case of
|
||||
* Attach to a DSA area created by the postmaster, in the case of
|
||||
* USE_DYNAMIC_HASH, also attach the local dshash handle to
|
||||
* the dshash created by the postmaster.
|
||||
*
|
||||
@@ -197,53 +193,54 @@ pgsm_create_bucket_hash(pgsmSharedState *pgsm, dsa_area *dsa)
|
||||
void
|
||||
pgsm_attach_shmem(void)
|
||||
{
|
||||
MemoryContext oldcontext;
|
||||
if (pgsmStateLocal.dsa)
|
||||
return;
|
||||
MemoryContext oldcontext;
|
||||
if (pgsmStateLocal.dsa)
|
||||
return;
|
||||
|
||||
/*
|
||||
* We want the dsa to remain valid throughout the lifecycle of this process.
|
||||
* so switch to TopMemoryContext before attaching
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
/*
|
||||
* We want the dsa to remain valid throughout the lifecycle of this
|
||||
* process. so switch to TopMemoryContext before attaching
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
pgsmStateLocal.dsa = dsa_attach_in_place(pgsmStateLocal.shared_pgsmState->raw_dsa_area,
|
||||
NULL);
|
||||
/* pin the attached area to keep the area attached until end of
|
||||
* session or explicit detach.
|
||||
*/
|
||||
dsa_pin_mapping(pgsmStateLocal.dsa);
|
||||
pgsmStateLocal.dsa = dsa_attach_in_place(pgsmStateLocal.shared_pgsmState->raw_dsa_area,
|
||||
NULL);
|
||||
/*
|
||||
* pin the attached area to keep the area attached until end of session or
|
||||
* explicit detach.
|
||||
*/
|
||||
dsa_pin_mapping(pgsmStateLocal.dsa);
|
||||
|
||||
#if USE_DYNAMIC_HASH
|
||||
dsh_params.tranche_id = pgsmStateLocal.shared_pgsmState->hash_tranche_id;
|
||||
pgsmStateLocal.shared_hash = dshash_attach(pgsmStateLocal.dsa, &dsh_params,
|
||||
pgsmStateLocal.shared_pgsmState->hash_handle, 0);
|
||||
dsh_params.tranche_id = pgsmStateLocal.shared_pgsmState->hash_tranche_id;
|
||||
pgsmStateLocal.shared_hash = dshash_attach(pgsmStateLocal.dsa, &dsh_params,
|
||||
pgsmStateLocal.shared_pgsmState->hash_handle, 0);
|
||||
#else
|
||||
pgsmStateLocal.shared_hash = pgsmStateLocal.shared_pgsmState->hash_handle;
|
||||
pgsmStateLocal.shared_hash = pgsmStateLocal.shared_pgsmState->hash_handle;
|
||||
#endif
|
||||
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
MemoryContextSwitchTo(oldcontext);
|
||||
}
|
||||
|
||||
dsa_area*
|
||||
dsa_area *
|
||||
get_dsa_area_for_query_text(void)
|
||||
{
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.dsa;
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.dsa;
|
||||
}
|
||||
|
||||
PGSM_HASH_TABLE*
|
||||
PGSM_HASH_TABLE *
|
||||
get_pgsmHash(void)
|
||||
{
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.shared_hash;
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.shared_hash;
|
||||
}
|
||||
|
||||
pgsmSharedState *
|
||||
pgsm_get_ss(void)
|
||||
{
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.shared_pgsmState;
|
||||
pgsm_attach_shmem();
|
||||
return pgsmStateLocal.shared_pgsmState;
|
||||
}
|
||||
|
||||
|
||||
@@ -256,48 +253,47 @@ pgsm_get_ss(void)
|
||||
void
|
||||
pgsm_shmem_shutdown(int code, Datum arg)
|
||||
{
|
||||
/* Don't try to dump during a crash. */
|
||||
elog(LOG,"[pg_stat_monitor] pgsm_shmem_shutdown: Shutdown initiated.");
|
||||
/* Don't try to dump during a crash. */
|
||||
elog(LOG, "[pg_stat_monitor] pgsm_shmem_shutdown: Shutdown initiated.");
|
||||
|
||||
if (code)
|
||||
return;
|
||||
if (code)
|
||||
return;
|
||||
|
||||
pgsmStateLocal.shared_pgsmState = NULL;
|
||||
/* Safety check ... shouldn't get here unless shmem is set up. */
|
||||
if (!IsHashInitialize())
|
||||
return;
|
||||
pgsmStateLocal.shared_pgsmState = NULL;
|
||||
/* Safety check ... shouldn't get here unless shmem is set up. */
|
||||
if (!IsHashInitialize())
|
||||
return;
|
||||
}
|
||||
|
||||
pgsmEntry *
|
||||
hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
|
||||
pgsmEntry *
|
||||
hash_entry_alloc(pgsmSharedState * pgsm, pgsmHashKey * key, int encoding)
|
||||
{
|
||||
pgsmEntry *entry = NULL;
|
||||
bool found = false;
|
||||
/* Find or create an entry with desired hash code */
|
||||
entry = (pgsmEntry*) pgsm_hash_find_or_insert(pgsmStateLocal.shared_hash, key, &found);
|
||||
if (entry == NULL)
|
||||
elog(DEBUG1, "[pg_stat_monitor] hash_entry_alloc: OUT OF MEMORY.");
|
||||
else if (!found)
|
||||
{
|
||||
pgsm->bucket_entry[pg_atomic_read_u64(&pgsm->current_wbucket)]++;
|
||||
/* New entry, initialize it */
|
||||
/* reset the statistics */
|
||||
memset(&entry->counters, 0, sizeof(Counters));
|
||||
entry->query_text.query_pos = InvalidDsaPointer;
|
||||
entry->counters.info.parent_query = InvalidDsaPointer;
|
||||
pgsmEntry *entry = NULL;
|
||||
bool found = false;
|
||||
/* Find or create an entry with desired hash code */
|
||||
entry = (pgsmEntry *) pgsm_hash_find_or_insert(pgsmStateLocal.shared_hash, key, &found);
|
||||
if (entry == NULL)
|
||||
elog(DEBUG1, "[pg_stat_monitor] hash_entry_alloc: OUT OF MEMORY.");
|
||||
else if (!found) {
|
||||
pgsm->bucket_entry[pg_atomic_read_u64(&pgsm->current_wbucket)]++;
|
||||
/* New entry, initialize it */
|
||||
/* reset the statistics */
|
||||
memset(&entry->counters, 0, sizeof(Counters));
|
||||
entry->query_text.query_pos = InvalidDsaPointer;
|
||||
entry->counters.info.parent_query = InvalidDsaPointer;
|
||||
|
||||
/* set the appropriate initial usage count */
|
||||
/* re-initialize the mutex each time ... we assume no one using it */
|
||||
SpinLockInit(&entry->mutex);
|
||||
/* ... and don't forget the query text metadata */
|
||||
entry->encoding = encoding;
|
||||
}
|
||||
#if USE_DYNAMIC_HASH
|
||||
if(entry)
|
||||
dshash_release_lock(pgsmStateLocal.shared_hash, entry);
|
||||
#endif
|
||||
/* set the appropriate initial usage count */
|
||||
/* re-initialize the mutex each time ... we assume no one using it */
|
||||
SpinLockInit(&entry->mutex);
|
||||
/* ... and don't forget the query text metadata */
|
||||
entry->encoding = encoding;
|
||||
}
|
||||
#if USE_DYNAMIC_HASH
|
||||
if (entry)
|
||||
dshash_release_lock(pgsmStateLocal.shared_hash, entry);
|
||||
#endif
|
||||
|
||||
return entry;
|
||||
return entry;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -315,54 +311,52 @@ hash_entry_alloc(pgsmSharedState *pgsm, pgsmHashKey *key, int encoding)
|
||||
void
|
||||
hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *query_buffer)
|
||||
{
|
||||
PGSM_HASH_SEQ_STATUS hstat;
|
||||
pgsmEntry *entry = NULL;
|
||||
/* Store pending query ids from the previous bucket. */
|
||||
PGSM_HASH_SEQ_STATUS hstat;
|
||||
pgsmEntry *entry = NULL;
|
||||
/* Store pending query ids from the previous bucket. */
|
||||
|
||||
if (!pgsmStateLocal.shared_hash)
|
||||
return;
|
||||
if (!pgsmStateLocal.shared_hash)
|
||||
return;
|
||||
|
||||
/* Iterate over the hash table. */
|
||||
pgsm_hash_seq_init(&hstat, pgsmStateLocal.shared_hash, true);
|
||||
/* Iterate over the hash table. */
|
||||
pgsm_hash_seq_init(&hstat, pgsmStateLocal.shared_hash, true);
|
||||
|
||||
while ((entry = pgsm_hash_seq_next(&hstat)) != NULL)
|
||||
{
|
||||
dsa_pointer pdsa;
|
||||
while ((entry = pgsm_hash_seq_next(&hstat)) != NULL) {
|
||||
dsa_pointer pdsa;
|
||||
|
||||
/*
|
||||
* Remove all entries if new_bucket_id == -1. Otherwise remove entry
|
||||
* in new_bucket_id if it has finished already.
|
||||
*/
|
||||
if (new_bucket_id < 0 ||
|
||||
(entry->key.bucket_id == new_bucket_id ))
|
||||
{
|
||||
dsa_pointer parent_qdsa = entry->counters.info.parent_query;
|
||||
pdsa = entry->query_text.query_pos;
|
||||
/*
|
||||
* Remove all entries if new_bucket_id == -1. Otherwise remove entry
|
||||
* in new_bucket_id if it has finished already.
|
||||
*/
|
||||
if (new_bucket_id < 0 ||
|
||||
(entry->key.bucket_id == new_bucket_id)) {
|
||||
dsa_pointer parent_qdsa = entry->counters.info.parent_query;
|
||||
pdsa = entry->query_text.query_pos;
|
||||
|
||||
pgsm_hash_delete_current(&hstat, pgsmStateLocal.shared_hash, &entry->key);
|
||||
pgsm_hash_delete_current(&hstat, pgsmStateLocal.shared_hash, &entry->key);
|
||||
|
||||
if (DsaPointerIsValid(pdsa))
|
||||
dsa_free(pgsmStateLocal.dsa, pdsa);
|
||||
if (DsaPointerIsValid(pdsa))
|
||||
dsa_free(pgsmStateLocal.dsa, pdsa);
|
||||
|
||||
if (DsaPointerIsValid(parent_qdsa))
|
||||
dsa_free(pgsmStateLocal.dsa, parent_qdsa);
|
||||
if (DsaPointerIsValid(parent_qdsa))
|
||||
dsa_free(pgsmStateLocal.dsa, parent_qdsa);
|
||||
|
||||
pgsmStateLocal.shared_pgsmState->pgsm_oom = false;
|
||||
}
|
||||
pgsmStateLocal.shared_pgsmState->pgsm_oom = false;
|
||||
}
|
||||
pgsm_hash_seq_term(&hstat);
|
||||
}
|
||||
pgsm_hash_seq_term(&hstat);
|
||||
}
|
||||
|
||||
bool
|
||||
IsHashInitialize(void)
|
||||
{
|
||||
return (pgsmStateLocal.shared_pgsmState != NULL);
|
||||
return (pgsmStateLocal.shared_pgsmState != NULL);
|
||||
}
|
||||
|
||||
bool
|
||||
IsSystemOOM(void)
|
||||
{
|
||||
return (IsHashInitialize() && pgsmStateLocal.shared_pgsmState->pgsm_oom);
|
||||
return (IsHashInitialize() && pgsmStateLocal.shared_pgsmState->pgsm_oom);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -370,62 +364,62 @@ IsSystemOOM(void)
|
||||
* API and call the appropriate hash table function based on USE_DYNAMIC_HASH
|
||||
*/
|
||||
|
||||
void *
|
||||
pgsm_hash_find_or_insert(PGSM_HASH_TABLE *shared_hash, pgsmHashKey *key, bool* found)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
void *entry;
|
||||
entry = dshash_find_or_insert(shared_hash, key, found);
|
||||
return entry;
|
||||
#else
|
||||
return hash_search(shared_hash, key, HASH_ENTER_NULL, found);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *
|
||||
pgsm_hash_find(PGSM_HASH_TABLE *shared_hash, pgsmHashKey *key, bool* found)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
return dshash_find(shared_hash, key, false);
|
||||
#else
|
||||
return hash_search(shared_hash, key, HASH_FIND, found);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS *hstat, PGSM_HASH_TABLE *shared_hash, bool lock)
|
||||
void *
|
||||
pgsm_hash_find_or_insert(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool *found)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_seq_init(hstat, shared_hash, lock);
|
||||
void *entry;
|
||||
entry = dshash_find_or_insert(shared_hash, key, found);
|
||||
return entry;
|
||||
#else
|
||||
hash_seq_init(hstat, shared_hash);
|
||||
return hash_search(shared_hash, key, HASH_ENTER_NULL, found);
|
||||
#endif
|
||||
}
|
||||
|
||||
void*
|
||||
pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS *hstat)
|
||||
void *
|
||||
pgsm_hash_find(PGSM_HASH_TABLE * shared_hash, pgsmHashKey * key, bool *found)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
return dshash_seq_next(hstat);
|
||||
return dshash_find(shared_hash, key, false);
|
||||
#else
|
||||
return hash_seq_search(hstat);
|
||||
return hash_search(shared_hash, key, HASH_FIND, found);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS *hstat)
|
||||
pgsm_hash_seq_init(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, bool lock)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_seq_term(hstat);
|
||||
dshash_seq_init(hstat, shared_hash, lock);
|
||||
#else
|
||||
hash_seq_init(hstat, shared_hash);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *
|
||||
pgsm_hash_seq_next(PGSM_HASH_SEQ_STATUS * hstat)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
return dshash_seq_next(hstat);
|
||||
#else
|
||||
return hash_seq_search(hstat);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS *hstat, PGSM_HASH_TABLE *shared_hash, void *key)
|
||||
pgsm_hash_seq_term(PGSM_HASH_SEQ_STATUS * hstat)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_delete_current(hstat);
|
||||
#else
|
||||
hash_search(shared_hash, key, HASH_REMOVE, NULL);
|
||||
#endif
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_seq_term(hstat);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
pgsm_hash_delete_current(PGSM_HASH_SEQ_STATUS * hstat, PGSM_HASH_TABLE * shared_hash, void *key)
|
||||
{
|
||||
#if USE_DYNAMIC_HASH
|
||||
dshash_delete_current(hstat);
|
||||
#else
|
||||
hash_search(shared_hash, key, HASH_REMOVE, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user