* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
+/*
+ * 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/.
+ */
+
/*
* MT safe ; FIXME: might still freeze, watch out, not thoroughly
* looked at yet.
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,
+static inline gpointer g_data_set_internal (GData **datalist,
GQuark key_id,
gpointer data,
GDestroyNotify destroy_func,
/* --- variables --- */
-static G_LOCK_DEFINE(g_dataset_global);
+G_LOCK_DEFINE_STATIC (g_dataset_global);
static GHashTable *g_dataset_location_ht = NULL;
static GDataset *g_dataset_cached = NULL; /* should this be
threadspecific? */
static GData *g_data_cache = NULL;
static guint g_data_cache_length = 0;
-static G_LOCK_DEFINE(g_quark_global);
+G_LOCK_DEFINE_STATIC (g_quark_global);
static GHashTable *g_quark_ht = NULL;
static gchar **g_quarks = NULL;
static GQuark g_quark_seq_id = 0;
list = prev->next;
if (prev->destroy_func)
- prev->destroy_func (prev->data);
+ {
+ G_UNLOCK (g_dataset_global);
+ prev->destroy_func (prev->data);
+ G_LOCK (g_dataset_global);
+ }
if (g_data_cache_length < G_DATA_CACHE_MAX)
{
{
g_return_if_fail (datalist != NULL);
- g_lock (g_dataset_global);
+ G_LOCK (g_dataset_global);
if (!g_dataset_location_ht)
g_data_initialize ();
while (*datalist)
g_datalist_clear_i (datalist);
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
}
/* HOLDS: g_dataset_global_lock */
{
g_return_if_fail (dataset_location != NULL);
- g_lock (g_dataset_global);
+ G_LOCK (g_dataset_global);
if (g_dataset_location_ht)
{
register GDataset *dataset;
if (dataset)
g_dataset_destroy_internal (dataset);
}
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
}
/* HOLDS: g_dataset_global_lock */
-static inline void
+static inline gpointer
g_data_set_internal (GData **datalist,
GQuark key_id,
gpointer data,
{
if (list->id == key_id)
{
+ gpointer ret_data = NULL;
+
if (prev)
prev->next = list->next;
else
* data without destroy notification
*/
if (list->destroy_func && !destroy_func)
- list->destroy_func (list->data);
+ {
+ G_UNLOCK (g_dataset_global);
+ list->destroy_func (list->data);
+ G_LOCK (g_dataset_global);
+ }
+ else
+ ret_data = list->data;
if (g_data_cache_length < G_DATA_CACHE_MAX)
{
else
g_mem_chunk_free (g_data_mem_chunk, list);
- return;
+ return ret_data;
}
prev = list;
/* we need to have updated all structures prior to
* invokation of the destroy function
*/
+ G_UNLOCK (g_dataset_global);
dfunc (ddata);
+ G_LOCK (g_dataset_global);
}
- return;
+ return NULL;
}
list = list->next;
list->destroy_func = destroy_func;
*datalist = list;
}
+
+ return NULL;
}
void
return;
}
- g_lock (g_dataset_global);
+ G_LOCK (g_dataset_global);
if (!g_dataset_location_ht)
g_data_initialize ();
}
g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset);
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
}
void
return;
}
- g_lock (g_dataset_global);
+ G_LOCK (g_dataset_global);
if (!g_dataset_location_ht)
g_data_initialize ();
g_data_set_internal (datalist, key_id, data, destroy_func, NULL);
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
}
-void
+gpointer
g_dataset_id_remove_no_notify (gconstpointer dataset_location,
GQuark key_id)
{
- g_return_if_fail (dataset_location != NULL);
+ gpointer ret_data = NULL;
+
+ g_return_val_if_fail (dataset_location != NULL, NULL);
- g_lock (g_dataset_global);
+ G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht)
{
GDataset *dataset;
dataset = g_dataset_lookup (dataset_location);
if (dataset)
- g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset);
+ ret_data = g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset);
}
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
+
+ return ret_data;
}
-void
+gpointer
g_datalist_id_remove_no_notify (GData **datalist,
GQuark key_id)
{
- g_return_if_fail (datalist != NULL);
+ gpointer ret_data = NULL;
- g_lock (g_dataset_global);
+ g_return_val_if_fail (datalist != NULL, NULL);
+
+ G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht)
- g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL);
- g_unlock (g_dataset_global);
+ ret_data = g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL);
+ G_UNLOCK (g_dataset_global);
+
+ return ret_data;
}
gpointer
{
g_return_val_if_fail (dataset_location != NULL, NULL);
- g_lock (g_dataset_global);
+ G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht)
{
register GDataset *dataset;
for (list = dataset->datalist; list; list = list->next)
if (list->id == key_id)
{
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
return list->data;
}
}
}
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
return NULL;
}
g_return_if_fail (dataset_location != NULL);
g_return_if_fail (func != NULL);
- g_lock (g_dataset_global);
+ G_LOCK (g_dataset_global);
if (g_dataset_location_ht)
{
dataset = g_dataset_lookup (dataset_location);
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
if (dataset)
{
register GData *list;
}
else
{
- g_unlock (g_dataset_global);
+ G_UNLOCK (g_dataset_global);
}
}
GQuark quark = 0;
g_return_val_if_fail (string != NULL, 0);
- g_lock (g_quark_global);
+ G_LOCK (g_quark_global);
if (g_quark_ht)
quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
- g_unlock (g_quark_global);
+ G_UNLOCK (g_quark_global);
return quark;
}
g_return_val_if_fail (string != NULL, 0);
- g_lock (g_quark_global);
+ G_LOCK (g_quark_global);
if (g_quark_ht)
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
else
if (!quark)
quark = g_quark_new (g_strdup (string));
- g_unlock (g_quark_global);
+ G_UNLOCK (g_quark_global);
return quark;
}
g_return_val_if_fail (string != NULL, 0);
- g_lock (g_quark_global);
+ G_LOCK (g_quark_global);
if (g_quark_ht)
quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
else
if (!quark)
quark = g_quark_new ((gchar*) string);
- g_unlock (g_quark_global);
+ G_UNLOCK (g_quark_global);
return quark;
}
g_quark_to_string (GQuark quark)
{
gchar* result = NULL;
- g_lock (g_quark_global);
+ G_LOCK (g_quark_global);
if (quark > 0 && quark <= g_quark_seq_id)
result = g_quarks[quark - 1];
- g_unlock (g_quark_global);
+ G_UNLOCK (g_quark_global);
return result;
}