1998-06-11 01:21:14 +02:00
|
|
|
/* GLIB - Library of useful routines for C programming
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* gdataset.c: Generic dataset mechanism, similar to GtkObject data.
|
|
|
|
* Copyright (C) 1998 Tim Janik
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
1998-12-15 06:28:02 +01:00
|
|
|
|
1999-02-24 07:14:27 +01:00
|
|
|
/*
|
|
|
|
* Modified by the GLib Team and others 1997-1999. See the AUTHORS
|
|
|
|
* file for a list of people on the GLib Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/*
|
|
|
|
* MT safe ; FIXME: might still freeze, watch out, not thoroughly
|
|
|
|
* looked at yet.
|
|
|
|
*/
|
|
|
|
|
1998-06-12 03:04:15 +02:00
|
|
|
#include <string.h>
|
1998-06-11 01:21:14 +02:00
|
|
|
#include "glib.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* --- defines --- */
|
1998-09-17 06:59:41 +02:00
|
|
|
#define G_QUARK_BLOCK_SIZE (512)
|
|
|
|
#define G_DATA_MEM_CHUNK_PREALLOC (128)
|
|
|
|
#define G_DATA_CACHE_MAX (512)
|
|
|
|
#define G_DATASET_MEM_CHUNK_PREALLOC (32)
|
1998-06-11 01:21:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* --- structures --- */
|
|
|
|
typedef struct _GDataset GDataset;
|
1998-09-17 06:59:41 +02:00
|
|
|
struct _GData
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
1998-09-17 06:59:41 +02:00
|
|
|
GData *next;
|
1998-09-18 20:16:49 +02:00
|
|
|
GQuark id;
|
1998-06-11 01:21:14 +02:00
|
|
|
gpointer data;
|
|
|
|
GDestroyNotify destroy_func;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GDataset
|
|
|
|
{
|
|
|
|
gconstpointer location;
|
1998-09-18 20:16:49 +02:00
|
|
|
GData *datalist;
|
1998-06-11 01:21:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* --- prototypes --- */
|
1998-09-18 20:16:49 +02:00
|
|
|
static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
|
|
|
|
static inline void g_datalist_clear_i (GData **datalist);
|
|
|
|
static void g_dataset_destroy_internal (GDataset *dataset);
|
|
|
|
static inline void g_data_set_internal (GData **datalist,
|
|
|
|
GQuark key_id,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy_func,
|
|
|
|
GDataset *dataset);
|
1998-09-17 06:59:41 +02:00
|
|
|
static void g_data_initialize (void);
|
1998-11-24 13:18:22 +01:00
|
|
|
static inline GQuark g_quark_new (gchar *string);
|
1998-06-19 04:00:23 +02:00
|
|
|
|
1998-06-11 01:21:14 +02:00
|
|
|
|
|
|
|
/* --- variables --- */
|
1999-02-10 10:40:46 +01:00
|
|
|
G_LOCK_DEFINE_STATIC (g_dataset_global);
|
1998-06-19 04:00:23 +02:00
|
|
|
static GHashTable *g_dataset_location_ht = NULL;
|
1998-12-15 06:28:02 +01:00
|
|
|
static GDataset *g_dataset_cached = NULL; /* should this be
|
|
|
|
threadspecific? */
|
1998-06-19 04:00:23 +02:00
|
|
|
static GMemChunk *g_dataset_mem_chunk = NULL;
|
1998-09-17 06:59:41 +02:00
|
|
|
static GMemChunk *g_data_mem_chunk = NULL;
|
|
|
|
static GData *g_data_cache = NULL;
|
|
|
|
static guint g_data_cache_length = 0;
|
1998-12-15 06:28:02 +01:00
|
|
|
|
1999-02-10 10:40:46 +01:00
|
|
|
G_LOCK_DEFINE_STATIC (g_quark_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
static GHashTable *g_quark_ht = NULL;
|
|
|
|
static gchar **g_quarks = NULL;
|
|
|
|
static GQuark g_quark_seq_id = 0;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* --- functions --- */
|
1998-12-15 06:28:02 +01:00
|
|
|
|
|
|
|
/* HOLDS: g_dataset_global_lock */
|
1998-09-17 06:59:41 +02:00
|
|
|
static inline void
|
1998-09-18 20:16:49 +02:00
|
|
|
g_datalist_clear_i (GData **datalist)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
|
|
|
register GData *list;
|
|
|
|
|
|
|
|
/* unlink *all* items before walking their destructors
|
|
|
|
*/
|
|
|
|
list = *datalist;
|
|
|
|
*datalist = NULL;
|
|
|
|
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
register GData *prev;
|
|
|
|
|
|
|
|
prev = list;
|
|
|
|
list = prev->next;
|
|
|
|
|
|
|
|
if (prev->destroy_func)
|
|
|
|
prev->destroy_func (prev->data);
|
|
|
|
|
|
|
|
if (g_data_cache_length < G_DATA_CACHE_MAX)
|
|
|
|
{
|
|
|
|
prev->next = g_data_cache;
|
|
|
|
g_data_cache = prev;
|
|
|
|
g_data_cache_length++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_mem_chunk_free (g_data_mem_chunk, prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-09-18 20:16:49 +02:00
|
|
|
g_datalist_clear (GData **datalist)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (datalist != NULL);
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
if (!g_dataset_location_ht)
|
|
|
|
g_data_initialize ();
|
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
while (*datalist)
|
|
|
|
g_datalist_clear_i (datalist);
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
}
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/* HOLDS: g_dataset_global_lock */
|
1998-06-11 01:21:14 +02:00
|
|
|
static inline GDataset*
|
|
|
|
g_dataset_lookup (gconstpointer dataset_location)
|
|
|
|
{
|
|
|
|
register GDataset *dataset;
|
|
|
|
|
|
|
|
if (g_dataset_cached && g_dataset_cached->location == dataset_location)
|
|
|
|
return g_dataset_cached;
|
|
|
|
|
|
|
|
dataset = g_hash_table_lookup (g_dataset_location_ht, dataset_location);
|
|
|
|
if (dataset)
|
|
|
|
g_dataset_cached = dataset;
|
|
|
|
|
|
|
|
return dataset;
|
|
|
|
}
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/* HOLDS: g_dataset_global_lock */
|
1998-09-17 06:59:41 +02:00
|
|
|
static void
|
|
|
|
g_dataset_destroy_internal (GDataset *dataset)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
1998-09-18 20:16:49 +02:00
|
|
|
register gconstpointer dataset_location;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
1998-09-18 20:16:49 +02:00
|
|
|
dataset_location = dataset->location;
|
|
|
|
while (dataset)
|
|
|
|
{
|
|
|
|
if (!dataset->datalist)
|
|
|
|
{
|
|
|
|
if (dataset == g_dataset_cached)
|
|
|
|
g_dataset_cached = NULL;
|
|
|
|
g_hash_table_remove (g_dataset_location_ht, dataset_location);
|
|
|
|
g_mem_chunk_free (g_dataset_mem_chunk, dataset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_datalist_clear_i (&dataset->datalist);
|
|
|
|
dataset = g_dataset_lookup (dataset_location);
|
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_dataset_destroy (gconstpointer dataset_location)
|
|
|
|
{
|
|
|
|
g_return_if_fail (dataset_location != NULL);
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
if (g_dataset_location_ht)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
1998-09-18 20:16:49 +02:00
|
|
|
register GDataset *dataset;
|
|
|
|
|
1998-06-11 01:21:14 +02:00
|
|
|
dataset = g_dataset_lookup (dataset_location);
|
|
|
|
if (dataset)
|
1998-09-17 06:59:41 +02:00
|
|
|
g_dataset_destroy_internal (dataset);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/* HOLDS: g_dataset_global_lock */
|
1998-09-17 06:59:41 +02:00
|
|
|
static inline void
|
1998-09-18 20:16:49 +02:00
|
|
|
g_data_set_internal (GData **datalist,
|
1998-09-17 06:59:41 +02:00
|
|
|
GQuark key_id,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy_func,
|
1998-09-18 20:16:49 +02:00
|
|
|
GDataset *dataset)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
1998-09-17 06:59:41 +02:00
|
|
|
register GData *list;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
list = *datalist;
|
1998-06-11 01:21:14 +02:00
|
|
|
if (!data)
|
|
|
|
{
|
1998-09-17 06:59:41 +02:00
|
|
|
register GData *prev;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
if (list->id == key_id)
|
|
|
|
{
|
|
|
|
if (prev)
|
|
|
|
prev->next = list->next;
|
|
|
|
else
|
|
|
|
{
|
1998-09-17 06:59:41 +02:00
|
|
|
*datalist = list->next;
|
1998-06-11 01:21:14 +02:00
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
/* the dataset destruction *must* be done
|
|
|
|
* prior to invokation of the data destroy function
|
|
|
|
*/
|
1998-09-18 20:16:49 +02:00
|
|
|
if (!*datalist && dataset)
|
|
|
|
g_dataset_destroy_internal (dataset);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
/* the GData struct *must* already be unlinked
|
1998-11-24 13:18:22 +01:00
|
|
|
* when invoking the destroy function.
|
1998-10-08 08:32:49 +02:00
|
|
|
* we use (data==NULL && destroy_func!=NULL) as
|
|
|
|
* a special hint combination to "steal"
|
|
|
|
* data without destroy notification
|
1998-06-11 01:21:14 +02:00
|
|
|
*/
|
1998-10-08 08:32:49 +02:00
|
|
|
if (list->destroy_func && !destroy_func)
|
1998-06-11 01:21:14 +02:00
|
|
|
list->destroy_func (list->data);
|
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
if (g_data_cache_length < G_DATA_CACHE_MAX)
|
|
|
|
{
|
|
|
|
list->next = g_data_cache;
|
|
|
|
g_data_cache = list;
|
|
|
|
g_data_cache_length++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_mem_chunk_free (g_data_mem_chunk, list);
|
|
|
|
|
1998-06-19 04:00:23 +02:00
|
|
|
return;
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
prev = list;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
if (list->id == key_id)
|
|
|
|
{
|
1998-09-17 06:59:41 +02:00
|
|
|
if (!list->destroy_func)
|
|
|
|
{
|
|
|
|
list->data = data;
|
|
|
|
list->destroy_func = destroy_func;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
register GDestroyNotify dfunc;
|
|
|
|
register gpointer ddata;
|
|
|
|
|
|
|
|
dfunc = list->destroy_func;
|
|
|
|
ddata = list->data;
|
|
|
|
list->data = data;
|
|
|
|
list->destroy_func = destroy_func;
|
|
|
|
|
|
|
|
/* we need to have updated all structures prior to
|
|
|
|
* invokation of the destroy function
|
|
|
|
*/
|
|
|
|
dfunc (ddata);
|
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
|
1998-06-19 04:00:23 +02:00
|
|
|
return;
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
if (g_data_cache)
|
|
|
|
{
|
|
|
|
list = g_data_cache;
|
|
|
|
g_data_cache = list->next;
|
|
|
|
g_data_cache_length--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
list = g_chunk_new (GData, g_data_mem_chunk);
|
|
|
|
list->next = *datalist;
|
1998-06-11 01:21:14 +02:00
|
|
|
list->id = key_id;
|
|
|
|
list->data = data;
|
|
|
|
list->destroy_func = destroy_func;
|
1998-09-17 06:59:41 +02:00
|
|
|
*datalist = list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_dataset_id_set_data_full (gconstpointer dataset_location,
|
|
|
|
GQuark key_id,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy_func)
|
|
|
|
{
|
|
|
|
register GDataset *dataset;
|
|
|
|
|
|
|
|
g_return_if_fail (dataset_location != NULL);
|
1998-10-08 08:32:49 +02:00
|
|
|
if (!data)
|
|
|
|
g_return_if_fail (destroy_func == NULL);
|
1998-09-17 06:59:41 +02:00
|
|
|
if (!key_id)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
g_return_if_fail (key_id > 0);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
if (!g_dataset_location_ht)
|
|
|
|
g_data_initialize ();
|
1998-12-15 06:28:02 +01:00
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
dataset = g_dataset_lookup (dataset_location);
|
|
|
|
if (!dataset)
|
|
|
|
{
|
|
|
|
dataset = g_chunk_new (GDataset, g_dataset_mem_chunk);
|
|
|
|
dataset->location = dataset_location;
|
1998-09-18 20:16:49 +02:00
|
|
|
g_datalist_init (&dataset->datalist);
|
1998-09-17 06:59:41 +02:00
|
|
|
g_hash_table_insert (g_dataset_location_ht,
|
|
|
|
(gpointer) dataset->location,
|
|
|
|
dataset);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset);
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-09-18 20:16:49 +02:00
|
|
|
g_datalist_id_set_data_full (GData **datalist,
|
|
|
|
GQuark key_id,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify destroy_func)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (datalist != NULL);
|
1998-10-08 08:32:49 +02:00
|
|
|
if (!data)
|
|
|
|
g_return_if_fail (destroy_func == NULL);
|
1998-09-17 06:59:41 +02:00
|
|
|
if (!key_id)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
g_return_if_fail (key_id > 0);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
1998-11-24 13:18:22 +01:00
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
if (!g_dataset_location_ht)
|
|
|
|
g_data_initialize ();
|
1998-09-17 06:59:41 +02:00
|
|
|
|
|
|
|
g_data_set_internal (datalist, key_id, data, destroy_func, NULL);
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-10-08 08:32:49 +02:00
|
|
|
g_dataset_id_remove_no_notify (gconstpointer dataset_location,
|
|
|
|
GQuark key_id)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (dataset_location != NULL);
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-10-08 08:32:49 +02:00
|
|
|
if (key_id && g_dataset_location_ht)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
1998-10-08 08:32:49 +02:00
|
|
|
GDataset *dataset;
|
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
dataset = g_dataset_lookup (dataset_location);
|
|
|
|
if (dataset)
|
1998-10-08 08:32:49 +02:00
|
|
|
g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset);
|
1998-12-15 06:28:02 +01:00
|
|
|
}
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-10-08 08:32:49 +02:00
|
|
|
g_datalist_id_remove_no_notify (GData **datalist,
|
|
|
|
GQuark key_id)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (datalist != NULL);
|
1998-10-08 08:32:49 +02:00
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
if (key_id && g_dataset_location_ht)
|
1998-10-08 08:32:49 +02:00
|
|
|
g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL);
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gpointer
|
|
|
|
g_dataset_id_get_data (gconstpointer dataset_location,
|
|
|
|
GQuark key_id)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (dataset_location != NULL, NULL);
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-09-17 06:59:41 +02:00
|
|
|
if (key_id && g_dataset_location_ht)
|
|
|
|
{
|
|
|
|
register GDataset *dataset;
|
|
|
|
|
|
|
|
dataset = g_dataset_lookup (dataset_location);
|
|
|
|
if (dataset)
|
|
|
|
{
|
|
|
|
register GData *list;
|
|
|
|
|
|
|
|
for (list = dataset->datalist; list; list = list->next)
|
|
|
|
if (list->id == key_id)
|
1998-12-15 06:28:02 +01:00
|
|
|
{
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-12-15 06:28:02 +01:00
|
|
|
return list->data;
|
|
|
|
}
|
1998-09-17 06:59:41 +02:00
|
|
|
}
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-12-15 06:28:02 +01:00
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpointer
|
1998-09-18 20:16:49 +02:00
|
|
|
g_datalist_id_get_data (GData **datalist,
|
|
|
|
GQuark key_id)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (datalist != NULL, NULL);
|
|
|
|
|
|
|
|
if (key_id)
|
|
|
|
{
|
|
|
|
register GData *list;
|
|
|
|
|
|
|
|
for (list = *datalist; list; list = list->next)
|
|
|
|
if (list->id == key_id)
|
|
|
|
return list->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-09-18 20:16:49 +02:00
|
|
|
g_dataset_foreach (gconstpointer dataset_location,
|
|
|
|
GDataForeachFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
register GDataset *dataset;
|
|
|
|
|
|
|
|
g_return_if_fail (dataset_location != NULL);
|
|
|
|
g_return_if_fail (func != NULL);
|
1998-11-24 13:18:22 +01:00
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_dataset_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
if (g_dataset_location_ht)
|
1998-09-18 20:16:49 +02:00
|
|
|
{
|
1998-11-24 13:18:22 +01:00
|
|
|
dataset = g_dataset_lookup (dataset_location);
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
if (dataset)
|
|
|
|
{
|
|
|
|
register GData *list;
|
|
|
|
|
|
|
|
for (list = dataset->datalist; list; list = list->next)
|
1998-12-15 06:28:02 +01:00
|
|
|
func (list->id, list->data, user_data);
|
1998-11-24 13:18:22 +01:00
|
|
|
}
|
1998-09-18 20:16:49 +02:00
|
|
|
}
|
1998-12-15 06:28:02 +01:00
|
|
|
else
|
|
|
|
{
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_dataset_global);
|
1998-12-15 06:28:02 +01:00
|
|
|
}
|
1998-09-18 20:16:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_datalist_foreach (GData **datalist,
|
|
|
|
GDataForeachFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
register GData *list;
|
|
|
|
|
|
|
|
g_return_if_fail (datalist != NULL);
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
|
|
|
for (list = *datalist; list; list = list->next)
|
|
|
|
func (list->id, list->data, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_datalist_init (GData **datalist)
|
1998-09-17 06:59:41 +02:00
|
|
|
{
|
|
|
|
g_return_if_fail (datalist != NULL);
|
|
|
|
|
|
|
|
*datalist = NULL;
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/* HOLDS: g_dataset_global_lock */
|
1998-06-11 01:21:14 +02:00
|
|
|
static void
|
1998-09-17 06:59:41 +02:00
|
|
|
g_data_initialize (void)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
1998-11-24 13:18:22 +01:00
|
|
|
g_return_if_fail (g_dataset_location_ht == NULL);
|
|
|
|
|
|
|
|
g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
|
|
|
|
g_dataset_cached = NULL;
|
|
|
|
g_dataset_mem_chunk =
|
|
|
|
g_mem_chunk_new ("GDataset MemChunk",
|
|
|
|
sizeof (GDataset),
|
|
|
|
sizeof (GDataset) * G_DATASET_MEM_CHUNK_PREALLOC,
|
|
|
|
G_ALLOC_AND_FREE);
|
|
|
|
g_data_mem_chunk =
|
|
|
|
g_mem_chunk_new ("GData MemChunk",
|
|
|
|
sizeof (GData),
|
|
|
|
sizeof (GData) * G_DATA_MEM_CHUNK_PREALLOC,
|
|
|
|
G_ALLOC_AND_FREE);
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|
|
|
|
|
1998-06-19 04:00:23 +02:00
|
|
|
GQuark
|
|
|
|
g_quark_try_string (const gchar *string)
|
|
|
|
{
|
1998-12-15 06:28:02 +01:00
|
|
|
GQuark quark = 0;
|
1998-06-19 04:00:23 +02:00
|
|
|
g_return_val_if_fail (string != NULL, 0);
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_quark_global);
|
1998-06-19 04:00:23 +02:00
|
|
|
if (g_quark_ht)
|
1998-12-15 06:28:02 +01:00
|
|
|
quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_quark_global);
|
1998-12-15 06:28:02 +01:00
|
|
|
|
|
|
|
return quark;
|
1998-06-19 04:00:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GQuark
|
|
|
|
g_quark_from_string (const gchar *string)
|
|
|
|
{
|
|
|
|
GQuark quark;
|
|
|
|
|
|
|
|
g_return_val_if_fail (string != NULL, 0);
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_quark_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
if (g_quark_ht)
|
|
|
|
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
quark = 0;
|
|
|
|
}
|
1998-06-19 04:00:23 +02:00
|
|
|
|
|
|
|
if (!quark)
|
|
|
|
quark = g_quark_new (g_strdup (string));
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_quark_global);
|
1998-06-19 04:00:23 +02:00
|
|
|
|
|
|
|
return quark;
|
|
|
|
}
|
|
|
|
|
|
|
|
GQuark
|
|
|
|
g_quark_from_static_string (const gchar *string)
|
|
|
|
{
|
|
|
|
GQuark quark;
|
|
|
|
|
|
|
|
g_return_val_if_fail (string != NULL, 0);
|
|
|
|
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_quark_global);
|
1998-11-24 13:18:22 +01:00
|
|
|
if (g_quark_ht)
|
|
|
|
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
quark = 0;
|
|
|
|
}
|
|
|
|
|
1998-06-19 04:00:23 +02:00
|
|
|
if (!quark)
|
1998-11-24 13:18:22 +01:00
|
|
|
quark = g_quark_new ((gchar*) string);
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_quark_global);
|
1998-12-15 06:28:02 +01:00
|
|
|
|
1998-06-19 04:00:23 +02:00
|
|
|
return quark;
|
|
|
|
}
|
|
|
|
|
1998-06-11 05:38:33 +02:00
|
|
|
gchar*
|
1998-06-19 04:00:23 +02:00
|
|
|
g_quark_to_string (GQuark quark)
|
1998-06-11 01:21:14 +02:00
|
|
|
{
|
1998-12-15 06:28:02 +01:00
|
|
|
gchar* result = NULL;
|
1998-12-16 06:38:35 +01:00
|
|
|
G_LOCK (g_quark_global);
|
1998-06-19 04:00:23 +02:00
|
|
|
if (quark > 0 && quark <= g_quark_seq_id)
|
1998-12-15 06:28:02 +01:00
|
|
|
result = g_quarks[quark - 1];
|
1998-12-16 06:38:35 +01:00
|
|
|
G_UNLOCK (g_quark_global);
|
1998-12-15 06:28:02 +01:00
|
|
|
|
|
|
|
return result;
|
1998-06-11 05:38:33 +02:00
|
|
|
}
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/* HOLDS: g_quark_global_lock */
|
1998-06-19 04:00:23 +02:00
|
|
|
static inline GQuark
|
1998-11-24 13:18:22 +01:00
|
|
|
g_quark_new (gchar *string)
|
1998-06-11 05:38:33 +02:00
|
|
|
{
|
1998-06-19 04:00:23 +02:00
|
|
|
GQuark quark;
|
|
|
|
|
1998-09-17 06:59:41 +02:00
|
|
|
if (g_quark_seq_id % G_QUARK_BLOCK_SIZE == 0)
|
1998-11-24 13:18:22 +01:00
|
|
|
g_quarks = g_renew (gchar*, g_quarks, g_quark_seq_id + G_QUARK_BLOCK_SIZE);
|
1998-06-19 04:00:23 +02:00
|
|
|
|
1998-11-24 13:18:22 +01:00
|
|
|
g_quarks[g_quark_seq_id] = string;
|
1998-06-19 04:00:23 +02:00
|
|
|
g_quark_seq_id++;
|
|
|
|
quark = g_quark_seq_id;
|
1998-11-24 13:18:22 +01:00
|
|
|
g_hash_table_insert (g_quark_ht, string, GUINT_TO_POINTER (quark));
|
1998-06-11 01:21:14 +02:00
|
|
|
|
1998-06-19 04:00:23 +02:00
|
|
|
return quark;
|
1998-06-11 01:21:14 +02:00
|
|
|
}
|