Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

atoms.c File Reference


Detailed Description

Atom management.

An atom is a single piece of information that is likely to be shared and which is therefore only allocated once: all other instances point to the common object.

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "atoms.h"
#include "misc.h"
#include "glib-missing.h"
#include "walloc.h"
#include "override.h"

Data Structures

union  mem_chunk
struct  atom
 Atoms are ref-counted. More...
struct  table_desc
 Description of atom types. More...

Defines

#define ATOMS_SOURCE
#define ATOM_MAGIC_CHECK(a)
#define ATOM_SET_MAGIC(a)
#define ATOM_TYPE_MASK   ((size_t) 0x07)
#define ARENA_OFFSET   G_STRUCT_OFFSET(struct atom, arena)
#define atom_protect(a, size)
#define atom_unprotect(a, size)

Typedefs

typedef atom atom_t
 Atoms are ref-counted.
typedef size_t(* len_func_t )(gconstpointer v)
typedef const gchar *(* str_func_t )(gconstpointer v)
typedef table_desc table_desc_t
 Description of atom types.

Functions

atom_tatom_from_arena (gconstpointer key)
void atom_check (const atom_t *a)
atom_tatom_alloc (size_t size)
void atom_dealloc (atom_t *a, size_t size)
size_t str_len (gconstpointer v)
const gchar * str_str (gconstpointer v)
size_t guid_len (gconstpointer v)
const gchar * guid_str (gconstpointer v)
size_t sha1_len (gconstpointer v)
const gchar * sha1_str (gconstpointer v)
size_t tth_len (gconstpointer v)
const gchar * tth_str (gconstpointer v)
size_t uint64_len (gconstpointer v)
const gchar * uint64_str (gconstpointer v)
size_t filesize_len (gconstpointer v)
const gchar * filesize_str (gconstpointer v)
guint binary_hash (const guchar *key, guint len)
 Hash `len' bytes starting from `key'.
guint guid_hash (gconstpointer key)
 Hash a GUID (16 bytes).
gint guid_eq (gconstpointer a, gconstpointer b)
 Test two GUIDs for equality.
guint sha1_hash (gconstpointer key)
 Hash a SHA1 (20 bytes).
gint sha1_eq (gconstpointer a, gconstpointer b)
 Test two SHA1s for equality.
guint tth_hash (gconstpointer key)
 Hash a TTH (24 bytes).
gint tth_eq (gconstpointer a, gconstpointer b)
 Test two TTHs for equality.
gint uint64_eq (gconstpointer a, gconstpointer b)
 Test two 64-bit integers for equality.
guint uint64_hash (gconstpointer p)
 Calculate the 32-bit hash of a 64-bit integer.
gint filesize_eq (gconstpointer a, gconstpointer b)
 Test two filesize_t for equality.
guint filesize_hash (gconstpointer p)
 Calculate the 32-bit hash of a filesize_t.
void atoms_init (void)
 Initialize atom structures.
size_t atom_is_registered (enum atom_type type, gconstpointer key)
gconstpointer atom_get (enum atom_type type, gconstpointer key)
 Get atom of given `type', whose value is `key'.
void atom_free (enum atom_type type, gconstpointer key)
 Remove one reference from atom.
gboolean atom_warn_free (gpointer key, gpointer unused_value, gpointer udata)
 Warning about existing atom that should have been freed.
void atoms_close (void)
 Shutdown atom structures, freeing all remaining atoms.

Variables

table_desc_t atoms []
 The set of all atom types we know about.
GHashTable * ht_all_atoms


Define Documentation

#define ARENA_OFFSET   G_STRUCT_OFFSET(struct atom, arena)
 

#define ATOM_MAGIC_CHECK  ) 
 

#define atom_protect a,
size   ) 
 

#define ATOM_SET_MAGIC  ) 
 

#define ATOM_TYPE_MASK   ((size_t) 0x07)
 

#define atom_unprotect a,
size   ) 
 

#define ATOMS_SOURCE
 


Typedef Documentation

typedef struct atom atom_t
 

Atoms are ref-counted.

The reference count is held at the beginning of the data arena. What we return to the outside is a pointer to arena[], not to the atom structure.

typedef size_t(* len_func_t)(gconstpointer v)
 

typedef const gchar*(* str_func_t)(gconstpointer v)
 

typedef struct table_desc table_desc_t
 

Description of atom types.


Function Documentation

atom_t* atom_alloc size_t  size  )  [inline, static]
 

void atom_check const atom_t a  )  [inline, static]
 

void atom_dealloc atom_t a,
size_t  size
[inline, static]
 

void atom_free enum atom_type  type,
gconstpointer  key
 

Remove one reference from atom.

Dispose of atom if nobody references it anymore.

atom_t* atom_from_arena gconstpointer  key  )  [inline, static]
 

gconstpointer atom_get enum atom_type  type,
gconstpointer  key
 

Get atom of given `type', whose value is `key'.

If the atom does not exist yet, `key' is cloned and makes up the new atom.

Returns:
the atom's value.

size_t atom_is_registered enum atom_type  type,
gconstpointer  key
[inline, static]
 

gboolean atom_warn_free gpointer  key,
gpointer  unused_value,
gpointer  udata
[static]
 

Warning about existing atom that should have been freed.

void atoms_close void   ) 
 

Shutdown atom structures, freeing all remaining atoms.

void atoms_init void   ) 
 

Initialize atom structures.

guint binary_hash const guchar *  key,
guint  len
 

Hash `len' bytes starting from `key'.

gint filesize_eq gconstpointer  a,
gconstpointer  b
 

Test two filesize_t for equality.

Returns:
whether both referenced 64-bit integers are equal.

guint filesize_hash gconstpointer  p  ) 
 

Calculate the 32-bit hash of a filesize_t.

Returns:
the 32-bit hash value for the referenced 64-bit integer.

size_t filesize_len gconstpointer  unused_v  )  [static]
 

Returns:
length of a filesize_t.

const gchar * filesize_str gconstpointer  v  )  [static]
 

Returns:
printable form of a filesize_t, as pointer to static data.

gint guid_eq gconstpointer  a,
gconstpointer  b
 

Test two GUIDs for equality.

guint guid_hash gconstpointer  key  ) 
 

Hash a GUID (16 bytes).

size_t guid_len gconstpointer  unused_guid  )  [static]
 

Returns:
length of GUID.

const gchar * guid_str gconstpointer  v  )  [static]
 

Returns:
printable form of a GUID, as pointer to static data.

gint sha1_eq gconstpointer  a,
gconstpointer  b
 

Test two SHA1s for equality.

Attention:
NB: This routine is visible for the download mesh.

guint sha1_hash gconstpointer  key  ) 
 

Hash a SHA1 (20 bytes).

Attention:
NB: This routine is visible for the download mesh.

size_t sha1_len gconstpointer  unused_sha1  )  [static]
 

Returns:
length of SHA1.

const gchar * sha1_str gconstpointer  sha1  )  [static]
 

Returns:
printable form of a SHA1, as pointer to static data.

size_t str_len gconstpointer  v  )  [static]
 

Returns:
length of string + trailing NUL.

const gchar * str_str gconstpointer  v  )  [static]
 

Returns:
printable form of a string, i.e. self.

gint tth_eq gconstpointer  a,
gconstpointer  b
 

Test two TTHs for equality.

Attention:
NB: This routine is visible for the download mesh.

guint tth_hash gconstpointer  key  ) 
 

Hash a TTH (24 bytes).

size_t tth_len gconstpointer  unused_tth  )  [static]
 

Returns:
length of TTH.

const gchar * tth_str gconstpointer  tth  )  [static]
 

Returns:
printable form of a TTH, as pointer to static data.

gint uint64_eq gconstpointer  a,
gconstpointer  b
 

Test two 64-bit integers for equality.

Returns:
whether both referenced 64-bit integers are equal.

guint uint64_hash gconstpointer  p  ) 
 

Calculate the 32-bit hash of a 64-bit integer.

Returns:
the 32-bit hash value for the referenced 64-bit integer.

size_t uint64_len gconstpointer  unused_v  )  [static]
 

Returns:
length of a 64-bit integer.

const gchar * uint64_str gconstpointer  v  )  [static]
 

Returns:
printable form of a 64-bit integer, as pointer to static data.


Variable Documentation

table_desc_t atoms[] [static]
 

Initial value:

 {
    { "String", NULL, g_str_hash,  g_str_equal, str_len,    str_str  }, 
    { "GUID",   NULL, guid_hash,   guid_eq,     guid_len,   guid_str }, 
    { "SHA1",   NULL, sha1_hash,   sha1_eq,     sha1_len,   sha1_str }, 
    { "TTH",    NULL, tth_hash,    tth_eq,      tth_len,    tth_str },  
    { "uint64", NULL, uint64_hash, uint64_eq,   uint64_len, uint64_str},
    { "filesize",
        NULL, filesize_hash, filesize_eq, filesize_len, filesize_str},  
}
The set of all atom types we know about.

GHashTable* ht_all_atoms [static]
 


Generated on Sat Jun 30 17:53:25 2007 for gtk-gnutella by  doxygen 1.3.9.1