Veil
veil_variables.c File Reference

Functions for dealing with Veil variables. More...

#include "postgres.h"
#include "veil_datatypes.h"
#include "utils/hsearch.h"
#include "storage/shmem.h"
#include "veil_funcs.h"

Go to the source code of this file.

Macros

#define SESSION_HASH_ELEMS   32
 Baselines the number of session variables that can be created in each context.
 

Functions

static HTAB * create_session_hash ()
 Create, or attach to, a hash for session variables.
 
VarEntryvl_lookup_shared_variable (char *name)
 Define a new, or attach to an existing, shared variable. More...
 
VarEntryvl_lookup_variable (char *name)
 Lookup a variable by name, creating it as as a session variable if it does not already exist. More...
 
veil_variable_tvl_next_variable (veil_variable_t *prev)
 Return the next variable from a scan of the hash of variables. More...
 
void vl_ClearInt4Array (Int4Array *array)
 Reset all Int4 entries in an Int4Array (to zero). More...
 
Int4Arrayvl_NewInt4Array (Int4Array *current, bool shared, int32 min, int32 max)
 Return a newly initialised (zeroed) Int4Array. More...
 
void vl_Int4ArraySet (Int4Array *array, int32 idx, int32 value)
 Set an entry within an Int4Array. More...
 
int32 vl_Int4ArrayGet (Int4Array *array, int32 idx)
 Get an entry from an Int4Array. More...
 

Variables

static HTAB * session_hash = NULL
 This identifies the hash table for all session variables. More...
 

Detailed Description

Functions for dealing with Veil variables.

Author: Marc Munro
Copyright (c) 2005 - 2011 Marc Munro
License: BSD

Variables may be either session or shared, and are used to retain state between function calls. Shared variables are available to all suitably privileged sessions within a database. Session variables hold values that are private to a single session.

Definition in file veil_variables.c.

Function Documentation

◆ vl_lookup_shared_variable()

VarEntry* vl_lookup_shared_variable ( char *  name)

Define a new, or attach to an existing, shared variable.

Raise an ERROR if the variable already exists as a session variable or if we cannot create the variable due to resource limitations (out of memory, or out of space in the shared hash).

Parameters
nameThe name of the variable.
Returns
Pointer to the shared variable. If the variable is newly created by this call then it will be unitialised (ie it will have a NULL obj reference).

Definition at line 70 of file veil_variables.c.

References create_session_hash(), VarEntry::obj, session_hash, VarEntry::shared, and vl_get_shared_hash().

Referenced by veil_share().

◆ vl_lookup_variable()

VarEntry* vl_lookup_variable ( char *  name)

Lookup a variable by name, creating it as as a session variable if it does not already exist.

Parameters
nameThe name of the variable
Returns
Pointer to the shared or session variable. If the variable is newly created by this call then it will be unitialised (ie it will have a NULL obj reference).

Definition at line 122 of file veil_variables.c.

References create_session_hash(), VarEntry::obj, session_hash, VarEntry::shared, and vl_get_shared_hash().

Referenced by deserialise_bitmap(), deserialise_bitmap_array(), deserialise_bitmap_hash(), deserialise_int4array(), deserialise_int4var(), deserialise_range(), GetBitmap(), GetBitmapArray(), GetBitmapHash(), GetBitmapRef(), GetInt4Array(), GetInt4Var(), GetRange(), veil_clear_bitmap(), veil_clear_bitmap_array(), veil_clear_bitmap_hash(), veil_init_bitmap(), veil_init_bitmap_array(), veil_init_bitmap_hash(), veil_init_int4array(), and vl_serialise_var().

◆ vl_next_variable()

veil_variable_t* vl_next_variable ( veil_variable_t prev)

Return the next variable from a scan of the hash of variables.

Note that this function is not re-entrant.

Parameters
prevThe last variable retrieved by a scan, or NULL if starting a new scan.
Returns
The next variable encountered in the scan. NULL if we have finished.

Definition at line 167 of file veil_variables.c.

References create_session_hash(), VarEntry::key, veil_variable_t::name, VarEntry::obj, session_hash, VarEntry::shared, veil_variable_t::shared, Object::type, veil_variable_t::type, vl_get_shared_hash(), and vl_ObjTypeName().

Referenced by veil_variables().

◆ vl_ClearInt4Array()

void vl_ClearInt4Array ( Int4Array array)

Reset all Int4 entries in an Int4Array (to zero).

Parameters
arrayThe array to be reset.

Definition at line 224 of file veil_variables.c.

References Int4Array::array, Int4Array::arraymax, and Int4Array::arrayzero.

Referenced by veil_clear_int4array(), and vl_NewInt4Array().

◆ vl_NewInt4Array()

Int4Array* vl_NewInt4Array ( Int4Array current,
bool  shared,
int32  min,
int32  max 
)

Return a newly initialised (zeroed) Int4Array.

It may already exist in which case it will be re-used if possible. It may be created in either session or shared memory depending on the value of shared.

Parameters
currentPointer to an existing Int4Array if one exists.
sharedWhether to create the variable in shared or session memory.
minIndex of the first entry in the array.
maxIndex of the last entry in the array.

Definition at line 246 of file veil_variables.c.

References Int4Array::arraymax, Int4Array::arrayzero, Int4Array::type, vl_ClearInt4Array(), vl_malloc(), and vl_shmalloc().

Referenced by veil_init_int4array().

◆ vl_Int4ArraySet()

void vl_Int4ArraySet ( Int4Array array,
int32  idx,
int32  value 
)

Set an entry within an Int4Array.

If idx is outside of the acceptable range, raise an error.

Parameters
arrayThe Int4Array within which the entry is to be set.
idxThe index of the entry to be set.
valueThe value to which the entry will be set.

Definition at line 290 of file veil_variables.c.

References Int4Array::array, Int4Array::arraymax, and Int4Array::arrayzero.

Referenced by veil_int4array_set().

◆ vl_Int4ArrayGet()

int32 vl_Int4ArrayGet ( Int4Array array,
int32  idx 
)

Get an entry from an Int4Array.

If idx is outside of the acceptable range, raise an error.

Parameters
arrayThe Int4Array within from the entry is to be read.
idxThe index of the entry to be retrieved.
Returns
The value of the entry

Definition at line 314 of file veil_variables.c.

References Int4Array::array, Int4Array::arraymax, and Int4Array::arrayzero.

Referenced by veil_int4array_get().

Variable Documentation

◆ session_hash

HTAB* session_hash = NULL
static

This identifies the hash table for all session variables.

The shared variable hash tables are managed in veil_shmem.c.

Definition at line 36 of file veil_variables.c.

Referenced by vl_lookup_shared_variable(), vl_lookup_variable(), and vl_next_variable().