/** * g_dataset_foreach: * @dataset_location: the location identifying the dataset. * @func: the function to call for each data element. * @user_data: user data to pass to the function. * * Calls the given function for each data element which is associated * with the given location. Note that this function is NOT thread-safe. * So unless @datalist can be protected from any modifications during * invocation of this function, it should not be called. **/ void 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); G_LOCK (g_dataset_global); if (g_dataset_location_ht) { dataset = g_dataset_lookup (dataset_location); G_UNLOCK (g_dataset_global); if (dataset) { register GData *list, *next; for (list = dataset->datalist; list; list = next) { next = list->next; func (list->id, list->data, user_data); } } } else { G_UNLOCK (g_dataset_global); } }
/** * g_dataset_get_data: * @l: the location identifying the dataset. * @k: the string identifying the data element. * @Returns: the data element corresponding to the string, or %NULL if * it is not found. * * Gets the data element corresponding to a string. **/ gpointer g_dataset_id_get_data (gconstpointer dataset_location, GQuark key_id) { g_return_val_if_fail (dataset_location != NULL, NULL); G_LOCK (g_dataset_global); 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) { G_UNLOCK (g_dataset_global); return list->data; } } } G_UNLOCK (g_dataset_global); return NULL; }
/** * g_dataset_destroy: * @dataset_location: the location identifying the dataset. * * Destroys the dataset, freeing all memory allocated, and calling any * destroy functions set for data elements. **/ void g_dataset_destroy (gconstpointer dataset_location) { g_return_if_fail (dataset_location != NULL); G_LOCK (g_dataset_global); if (g_dataset_location_ht) { register GDataset *dataset; dataset = g_dataset_lookup (dataset_location); if (dataset) g_dataset_destroy_internal (dataset); } G_UNLOCK (g_dataset_global); }
/** * g_dataset_remove_data: * @l: the location identifying the dataset. * @k: the string identifying the data element. * * Removes a data element corresponding to a string. Its destroy * function is called if it has been set. **/ void g_dataset_id_set_data_full (gconstpointer dataset_location, GQuark key_id, gpointer data, GDestroyNotify destroy_func) { GDataset *dataset; g_return_if_fail (dataset_location != NULL); if (!data) g_return_if_fail (destroy_func == NULL); if (!key_id) { if (data) g_return_if_fail (key_id > 0); else return; } G_LOCK (g_dataset_global); if (!g_dataset_location_ht) g_data_initialize (); dataset = g_dataset_lookup (dataset_location); if (!dataset) { dataset = g_slice_new (GDataset); #ifdef GSTREAMER_LITE if (dataset == NULL) { G_UNLOCK (g_dataset_global); return; } #endif // GSTREAMER_LITE dataset->location = dataset_location; g_datalist_init (&dataset->datalist); g_hash_table_insert (g_dataset_location_ht, (gpointer) dataset->location, dataset); } g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset); G_UNLOCK (g_dataset_global); }
/** * g_dataset_remove_no_notify: * @l: the location identifying the dataset. * @k: the string identifying the data element. * * Removes an element, without calling its destroy notifier. **/ gpointer g_dataset_id_remove_no_notify (gconstpointer dataset_location, GQuark key_id) { gpointer ret_data = NULL; g_return_val_if_fail (dataset_location != NULL, NULL); G_LOCK (g_dataset_global); if (key_id && g_dataset_location_ht) { GDataset *dataset; dataset = g_dataset_lookup (dataset_location); if (dataset) ret_data = g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset); } G_UNLOCK (g_dataset_global); return ret_data; }
/* HOLDS: g_dataset_global_lock */ static void g_dataset_destroy_internal (GDataset *dataset) { register gconstpointer dataset_location; 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_slice_free (GDataset, dataset); break; } g_datalist_clear_i (&dataset->datalist); dataset = g_dataset_lookup (dataset_location); } }
/** * g_dataset_get_data: * @l: the location identifying the dataset. * @k: the string identifying the data element. * * Gets the data element corresponding to a string. * * Returns: (transfer none) (nullable): the data element corresponding to * the string, or %NULL if it is not found. **/ gpointer g_dataset_id_get_data (gconstpointer dataset_location, GQuark key_id) { gpointer retval = NULL; g_return_val_if_fail (dataset_location != NULL, NULL); G_LOCK (g_dataset_global); if (key_id && g_dataset_location_ht) { GDataset *dataset; dataset = g_dataset_lookup (dataset_location); if (dataset) retval = g_datalist_id_get_data (&dataset->datalist, key_id); } G_UNLOCK (g_dataset_global); return retval; }
/** * g_dataset_foreach: * @dataset_location: (not nullable): the location identifying the dataset. * @func: (scope call): the function to call for each data element. * @user_data: (closure): user data to pass to the function. * * Calls the given function for each data element which is associated * with the given location. Note that this function is NOT thread-safe. * So unless @dataset_location can be protected from any modifications * during invocation of this function, it should not be called. * * @func can make changes to the dataset, but the iteration will not * reflect changes made during the g_dataset_foreach() call, other * than skipping over elements that are removed. **/ void g_dataset_foreach (gconstpointer dataset_location, GDataForeachFunc func, gpointer user_data) { GDataset *dataset; g_return_if_fail (dataset_location != NULL); g_return_if_fail (func != NULL); G_LOCK (g_dataset_global); if (g_dataset_location_ht) { dataset = g_dataset_lookup (dataset_location); G_UNLOCK (g_dataset_global); if (dataset) g_datalist_foreach (&dataset->datalist, func, user_data); } else { G_UNLOCK (g_dataset_global); } }