XMMS2
Data Structures | Typedefs | Functions
s4_priv.h File Reference
#include <s4.h>
#include <glib.h>
#include <stdio.h>

Data Structures

struct  s4_St
 
struct  s4_intpair_t
 

Typedefs

typedef uint32_t log_number_t
 
typedef struct s4_index_data_St s4_index_data_t
 
typedef struct s4_const_data_St s4_const_data_t
 
typedef struct s4_entry_data_St s4_entry_data_t
 
typedef struct s4_log_data_St s4_log_data_t
 
typedef struct str_St str_t
 
typedef struct s4_index_St s4_index_t
 
typedef int(* index_function_t )(const s4_val_t *val, void *data)
 
typedef struct s4_lock_St s4_lock_t
 
typedef struct oplist_St oplist_t
 

Functions

void s4_set_errno (s4_errno_t err)
 Sets errno to the given error number. More...
 
void _start_sync (s4_t *s4)
 
void _sync (s4_t *s4)
 
int _reread_file (s4_t *s4)
 
int _s4_add_internal (s4_t *s4, const char *key_a, const s4_val_t *value_a, const char *key_b, const s4_val_t *value_b, const char *src)
 
s4_entry_data_t_entry_create_data (void)
 
void _entry_free_data (s4_entry_data_t *data)
 
s4_val_ts4_val_new_internal_string (const char *str, s4_t *s4)
 Creates a new internal string value. More...
 
const char * _string_lookup (s4_t *s4, const char *str)
 Gets a pointer to a constant string that's equal to str. More...
 
const char * _string_lookup_casefolded (s4_t *s4, const char *str)
 Gets the casefolded string corresponding to str. More...
 
const char * _string_lookup_collated (s4_t *s4, const char *str)
 Gets the collated string corresponding to str. More...
 
const s4_val_t_string_lookup_val (s4_t *s4, const char *str)
 Gets a pointer to a constant string value with a string equal to str. More...
 
const s4_val_t_int_lookup_val (s4_t *s4, int32_t i)
 
const s4_val_t_const_lookup (s4_t *s4, const s4_val_t *val)
 
s4_const_data_t_const_create_data (void)
 
void _const_free_data (s4_const_data_t *data)
 
s4_index_data_t_index_create_data (void)
 
void _index_free_data (s4_index_data_t *data)
 
s4_index_t_index_get_a (s4_t *s4, const char *key, int create)
 Gets the a-index associated with key. More...
 
s4_index_t_index_get_b (s4_t *s4, const char *key)
 Gets the b-index associated with key. More...
 
GList * _index_get_all_a (s4_t *s4)
 Gets all a-indexes. More...
 
GList * _index_get_all_b (s4_t *s4)
 Gets all b-indexes. More...
 
s4_index_t_index_create (void)
 Creates a new index. More...
 
int _index_add (s4_t *s4, const char *key, s4_index_t *index)
 Adds an index to a database. More...
 
int _index_insert (s4_index_t *index, const s4_val_t *val, void *data)
 Inserts a new value-data pair into the index. More...
 
int _index_delete (s4_index_t *index, const s4_val_t *val, void *data)
 Removes a value-data pair from the index. More...
 
GList * _index_search (s4_index_t *index, index_function_t func, void *data)
 Searches an index. More...
 
GList * _index_lsearch (s4_index_t *index, index_function_t func, void *data)
 Searches an index using a linear search. More...
 
void _index_free (s4_index_t *index)
 Frees an index. More...
 
int _index_lock_shared (s4_index_t *index, s4_transaction_t *trans)
 
int _index_lock_exclusive (s4_index_t *index, s4_transaction_t *trans)
 
int32_t s4_cond_get_ikey (s4_condition_t *cond)
 
void s4_cond_set_ikey (s4_condition_t *cond, int32_t ikey)
 
s4_result_ts4_result_create (s4_result_t *next, const char *key, const s4_val_t *val, const char *src)
 Creates a new result. More...
 
void s4_result_free (s4_result_t *res)
 Frees a result. More...
 
s4_resultrow_ts4_resultrow_create (int colcount)
 Creates a new row. More...
 
s4_resultrow_ts4_resultrow_ref (s4_resultrow_t *row)
 References a resultrow. More...
 
void s4_resultrow_unref (s4_resultrow_t *row)
 Unreferences a resultrow. More...
 
int _s4_add (s4_transaction_t *trans, const char *key_a, const s4_val_t *val_a, const char *key_b, const s4_val_t *val_b, const char *src)
 Adds a new relation to a database. More...
 
int _s4_del (s4_transaction_t *trans, const char *key_a, const s4_val_t *val_a, const char *key_b, const s4_val_t *val_b, const char *src)
 Deletes a relation from a database. More...
 
s4_resultset_t_s4_query (s4_transaction_t *trans, s4_fetchspec_t *fs, s4_condition_t *cond)
 Queries a database for all entries matching a condition, then fetches data from them. More...
 
void _free_relations (s4_t *s4)
 Frees all relations in a database. More...
 
s4_lock_t_lock_alloc (void)
 
void _lock_free (s4_lock_t *lock)
 
int _lock_exclusive (s4_lock_t *lock, s4_transaction_t *trans)
 
int _lock_shared (s4_lock_t *lock, s4_transaction_t *trans)
 
void _lock_unlock_all (s4_transaction_t *trans)
 
s4_t_transaction_get_db (s4_transaction_t *trans)
 
void _transaction_writing (s4_transaction_t *trans)
 
s4_lock_t_transaction_get_waiting_for (s4_transaction_t *trans)
 
void _transaction_set_waiting_for (s4_transaction_t *trans, s4_lock_t *waiting_for)
 
GList * _transaction_get_locks (s4_transaction_t *trans)
 
void _transaction_add_lock (s4_transaction_t *trans, s4_lock_t *lock)
 
void _transaction_set_deadlocked (s4_transaction_t *trans)
 
s4_transaction_t_transaction_dummy_alloc (s4_t *s4)
 
void _transaction_dummy_free (s4_transaction_t *trans)
 
int _transaction_get_flags (s4_transaction_t *trans)
 
oplist_t_oplist_new (s4_transaction_t *trans)
 
void _oplist_free (oplist_t *list)
 
s4_t_oplist_get_db (oplist_t *list)
 
s4_transaction_t_oplist_get_trans (oplist_t *list)
 
void _oplist_insert_add (oplist_t *list, const char *key_a, const s4_val_t *val_a, const char *key_b, const s4_val_t *val_b, const char *src)
 
void _oplist_insert_del (oplist_t *list, const char *key_a, const s4_val_t *val_a, const char *key_b, const s4_val_t *val_b, const char *src)
 
void _oplist_insert_writing (oplist_t *list)
 
int _oplist_get_add (oplist_t *list, const char **key_a, const s4_val_t **val_a, const char **key_b, const s4_val_t **val_b, const char **src)
 
int _oplist_get_del (oplist_t *list, const char **key_a, const s4_val_t **val_a, const char **key_b, const s4_val_t **val_b, const char **src)
 
int _oplist_get_writing (oplist_t *list)
 
int _oplist_next (oplist_t *list)
 
void _oplist_first (oplist_t *list)
 
void _oplist_last (oplist_t *list)
 
int _oplist_rollback (oplist_t *list)
 
int _oplist_execute (oplist_t *list, int rollback_on_failure)
 
s4_log_data_t_log_create_data (void)
 
void _log_free_data (s4_log_data_t *data)
 
void _log_lock_file (s4_t *s4)
 Locks the log file. More...
 
void _log_unlock_file (s4_t *s4)
 Unlocks the log file. More...
 
void _log_lock_db (s4_t *s4)
 Locks the database file. More...
 
void _log_unlock_db (s4_t *s4)
 Unlocks the database file. More...
 
int _log_write (oplist_t *list)
 Writes all the operations in an oplist to disk. More...
 
void _log_checkpoint (s4_t *s4)
 Writes a checkpoint entry to the log, marking that the database has finished being written to disk. More...
 
int _log_open (s4_t *s4)
 Opens a log file. More...
 
int _log_close (s4_t *s4)
 Closes the log file. More...
 
log_number_t _log_last_synced (s4_t *s4)
 
void _log_init (s4_t *s4, log_number_t last_checkpoint)
 

Typedef Documentation

typedef int(* index_function_t)(const s4_val_t *val, void *data)
typedef uint32_t log_number_t
typedef struct oplist_St oplist_t
typedef struct s4_const_data_St s4_const_data_t
typedef struct s4_entry_data_St s4_entry_data_t
typedef struct s4_index_data_St s4_index_data_t
typedef struct s4_index_St s4_index_t
typedef struct s4_lock_St s4_lock_t
typedef struct s4_log_data_St s4_log_data_t
typedef struct str_St str_t

Function Documentation

s4_const_data_t* _const_create_data ( void  )
void _const_free_data ( s4_const_data_t data)
const s4_val_t* _const_lookup ( s4_t s4,
const s4_val_t val 
)

Referenced by s4_add(), and s4_del().

int _index_add ( s4_t s4,
const char *  key,
s4_index_t index 
)

Adds an index to a database.

Parameters
s4The database to add the index to
keyThe key to associate the index with
indexThe index to insert
Returns
0 if the key already has an index, non-zero otherwise

Referenced by s4_open().

s4_index_t* _index_create ( void  )

Creates a new index.

Returns
A new index

Referenced by _index_get_a(), and s4_open().

s4_index_data_t* _index_create_data ( void  )

Referenced by _reread_file().

int _index_delete ( s4_index_t index,
const s4_val_t val,
void *  data 
)

Removes a value-data pair from the index.

Parameters
indexThe index to remove from
valThe value to remove
dataThe data to remove
Returns
0 if the value-data pair is not found, 1 otherwise

Referenced by _s4_del().

void _index_free ( s4_index_t index)

Frees an index.

The values and data is NOT freed

Parameters
indexThe index to free

Referenced by _index_create_data().

void _index_free_data ( s4_index_data_t data)

Referenced by _reread_file().

s4_index_t* _index_get_a ( s4_t s4,
const char *  key,
int  create 
)

Gets the a-index associated with key.

A a-index is used to lookup entries by the a-value. If an index has not yet been created for this key and create is non-zero, one will be created and returned.

Parameters
s4The database to look for the index in
keyThe key the index should be indexing
createCreates the index if it does not exist
Returns
The index, or NULL if it does not exist and create is 0.

Referenced by _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().

GList* _index_get_all_a ( s4_t s4)

Gets all a-indexes.

Parameters
s4The database to get the index of.
Returns
A list of indexes.

Referenced by _free_relations(), and _s4_query().

GList* _index_get_all_b ( s4_t s4)

Gets all b-indexes.

Parameters
s4The database to get the index of.
Returns
A list of indexes.
s4_index_t* _index_get_b ( s4_t s4,
const char *  key 
)

Gets the b-index associated with key.

A b-index is used to lookup entries by the b-value.

Parameters
s4The database to look for the index in
keyThe key the index should be indexing
Returns
The index, or NULL if it is not found

Referenced by _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().

int _index_insert ( s4_index_t index,
const s4_val_t val,
void *  new_data 
)

Inserts a new value-data pair into the index.

Parameters
indexThe index to insert into
valThe value to associate the data with
new_dataThe data
Returns
1

Referenced by _s4_add(), and _s4_add_internal().

int _index_lock_exclusive ( s4_index_t index,
s4_transaction_t trans 
)

Referenced by _s4_add(), and _s4_del().

int _index_lock_shared ( s4_index_t index,
s4_transaction_t trans 
)

Referenced by _s4_add(), _s4_del(), and _s4_query().

GList* _index_lsearch ( s4_index_t index,
index_function_t  func,
void *  func_data 
)

Searches an index using a linear search.

Parameters
indexThe index to search
funcThe function to use when searching. It should return 0 if the value matches, -1 if the value is too small and 1 if the value is too big,
func_dataData passed as the second argument to func
Returns
A GList where list->data is the data found matching

Referenced by _s4_query().

GList* _index_search ( s4_index_t index,
index_function_t  func,
void *  func_data 
)

Searches an index.

Parameters
indexThe index to search
funcThe function to use when searching. It must be monotonic, It should return 0 if the value matches, -1 if the value is too small and 1 if the value is too big,
func_dataData passed as the second argument to func
Returns
A GList where list->data is the data found matching

Referenced by _free_relations(), _s4_add(), _s4_add_internal(), _s4_del(), and _s4_query().

const s4_val_t* _int_lookup_val ( s4_t s4,
int32_t  i 
)

Referenced by _const_lookup().

int _oplist_execute ( oplist_t list,
int  rollback_on_failure 
)
void _oplist_first ( oplist_t list)

Referenced by _log_write(), and _oplist_execute().

void _oplist_free ( oplist_t list)
int _oplist_get_add ( oplist_t list,
const char **  key_a,
const s4_val_t **  val_a,
const char **  key_b,
const s4_val_t **  val_b,
const char **  src 
)
s4_t* _oplist_get_db ( oplist_t list)

Referenced by _log_write().

int _oplist_get_del ( oplist_t list,
const char **  key_a,
const s4_val_t **  val_a,
const char **  key_b,
const s4_val_t **  val_b,
const char **  src 
)
s4_transaction_t* _oplist_get_trans ( oplist_t list)
int _oplist_get_writing ( oplist_t list)

Referenced by _log_write().

void _oplist_insert_add ( oplist_t list,
const char *  key_a,
const s4_val_t val_a,
const char *  key_b,
const s4_val_t val_b,
const char *  src 
)

Referenced by s4_add().

void _oplist_insert_del ( oplist_t list,
const char *  key_a,
const s4_val_t val_a,
const char *  key_b,
const s4_val_t val_b,
const char *  src 
)

Referenced by s4_del().

void _oplist_insert_writing ( oplist_t list)

Referenced by _transaction_writing().

void _oplist_last ( oplist_t list)

Referenced by s4_abort(), and s4_commit().

oplist_t* _oplist_new ( s4_transaction_t trans)

Referenced by s4_begin().

int _oplist_next ( oplist_t list)

Referenced by _log_write(), and _oplist_execute().

int _oplist_rollback ( oplist_t list)
const char* _string_lookup ( s4_t s4,
const char *  str 
)

Gets a pointer to a constant string that's equal to str.

_string_lookup will always return the same pointer for the same string

Parameters
s4The database to look for the string in
strThe string to find the constant string of
Returns
A pointer to a string equal to str

Referenced by _string_lookup_casefolded(), _string_lookup_collated(), s4_add(), s4_cond_update_key(), s4_del(), and s4_fetchspec_update_key().

const char* _string_lookup_casefolded ( s4_t s4,
const char *  str 
)

Gets the casefolded string corresponding to str.

str must have been obtained by calling _string_lookup.

Parameters
s4The database to look in
strThe string to find the casefold string of
Returns
The casefolded string of str

Referenced by s4_val_get_casefolded_str().

const char* _string_lookup_collated ( s4_t s4,
const char *  str 
)

Gets the collated string corresponding to str.

str must have been obtained by calling _string_lookup.

Parameters
s4The database to look in
strThe string to find the collated string of
Returns
The collated string of str

Referenced by s4_val_get_collated_str().

const s4_val_t* _string_lookup_val ( s4_t s4,
const char *  str 
)

Gets a pointer to a constant string value with a string equal to str.

_string_lookup_val will always return the same value for the same string.

Parameters
s4The database to look for the string in
strThe string to find the constant string of
Returns
A pointer to a string value

Referenced by _const_lookup(), and _string_lookup().

int32_t s4_cond_get_ikey ( s4_condition_t cond)
void s4_cond_set_ikey ( s4_condition_t cond,
int32_t  ikey 
)