diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-12-18 15:32:27 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-12-18 15:32:27 (GMT) |
commit | b0bcf250999b2242019f137e38f52390a86e71cd (patch) | |
tree | f3436a3ddbbd4773005ecb891630a815ed001341 /src/arch/sharing | |
parent | 6bde4016160057a22234d4ed698903dca52ce162 (diff) |
Shared all Dalvik operands between all their users.
Diffstat (limited to 'src/arch/sharing')
-rw-r--r-- | src/arch/sharing/Makefile.am | 2 | ||||
-rw-r--r-- | src/arch/sharing/container-int.h | 51 | ||||
-rw-r--r-- | src/arch/sharing/container.c | 87 | ||||
-rw-r--r-- | src/arch/sharing/container.h | 59 | ||||
-rw-r--r-- | src/arch/sharing/instance.c | 4 | ||||
-rw-r--r-- | src/arch/sharing/instance.h | 2 | ||||
-rw-r--r-- | src/arch/sharing/manager.c | 128 | ||||
-rw-r--r-- | src/arch/sharing/manager.h | 14 |
8 files changed, 342 insertions, 5 deletions
diff --git a/src/arch/sharing/Makefile.am b/src/arch/sharing/Makefile.am index 46496c2..48c6636 100644 --- a/src/arch/sharing/Makefile.am +++ b/src/arch/sharing/Makefile.am @@ -2,6 +2,8 @@ noinst_LTLIBRARIES = libarchsharing.la libarchsharing_la_SOURCES = \ + container-int.h \ + container.h container.c \ instance-int.h \ instance.h instance.c \ manager.h manager.c diff --git a/src/arch/sharing/container-int.h b/src/arch/sharing/container-int.h new file mode 100644 index 0000000..2bc5395 --- /dev/null +++ b/src/arch/sharing/container-int.h @@ -0,0 +1,51 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * container-int.h - définitions internes propres aux intégrateurs de contenu + * + * Copyright (C) 2016 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _ARCH_SHARING_CONTAINER_INT_H +#define _ARCH_SHARING_CONTAINER_INT_H + + +#include "container.h" + + + +/* Assure la mise à jour du contenu d'un intégrateur. */ +typedef void (* replace_shared_fc) (GShareContainer *, GSharedInstance *, GSharedInstance *); + + +/* Règles de partage d'une instance GObject (interface) */ +struct _GShareContainerIface +{ + GTypeInterface base_iface; /* A laisser en premier */ + + replace_shared_fc replace; /* Mise à jour du conteneur */ + +}; + + +/* Redéfinition */ +typedef GShareContainerIface GShareContainerInterface; + + + +#endif /* _ARCH_SHARING_CONTAINER_INT_H */ diff --git a/src/arch/sharing/container.c b/src/arch/sharing/container.c new file mode 100644 index 0000000..b968dad --- /dev/null +++ b/src/arch/sharing/container.c @@ -0,0 +1,87 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * content.c - intégration de données partagées + * + * Copyright (C) 2016 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "container.h" + + +#include <assert.h> + + +#include "container-int.h" + + + +/* Procède à l'initialisation de l'interface d'intégration. */ +static void g_share_container_default_init(GShareContainerInterface *); + + + +/* Détermine le type d'une interface pour l'intégration de contenu partagé. */ +G_DEFINE_INTERFACE(GShareContainer, g_share_container, G_TYPE_OBJECT) + + +/****************************************************************************** +* * +* Paramètres : iface = interface GLib à initialiser. * +* * +* Description : Procède à l'initialisation de l'interface d'intégration. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_share_container_default_init(GShareContainerInterface *iface) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : instance = intégrateur à éventuellement manipuler. * +* old = ancien contenu à remplacer si besoin est. * +* new = nouveau contenu, potentiellement original. * +* * +* Description : Assure la mise à jour du contenu d'un intégrateur. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_share_container_replace(GShareContainer *container, GSharedInstance *old, GSharedInstance *new) +{ + GShareContainerIface *iface; /* Interface utilisée */ + + if (old != new) + { + iface = G_SHARE_CONTAINER_GET_IFACE(container); + + iface->replace(container, old, new); + + } + +} diff --git a/src/arch/sharing/container.h b/src/arch/sharing/container.h new file mode 100644 index 0000000..d1ac8b2 --- /dev/null +++ b/src/arch/sharing/container.h @@ -0,0 +1,59 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * content.h - prototypes pour l'intégration de données partagées + * + * Copyright (C) 2016 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _ARCH_SHARING_CONTAINER_H +#define _ARCH_SHARING_CONTAINER_H + + +#include <stdbool.h> +#include <glib-object.h> + + +#include "instance.h" + + + +#define G_TYPE_SHARE_CONTAINER (g_share_container_get_type()) +#define G_SHARE_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_SHARE_CONTAINER, GShareContainer)) +#define G_SHARE_CONTAINER_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_SHARE_CONTAINER, GShareContainerIface)) +#define GTK_IS_SHARE_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_SHARE_CONTAINER)) +#define GTK_IS_SHARE_CONTAINER_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_SHARE_CONTAINER)) +#define G_SHARE_CONTAINER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_SHARE_CONTAINER, GShareContainerIface)) + + +/* Intégrateur de contenu partagé (coquille vide) */ +typedef struct _GShareContainer GShareContainer; + +/* Intégrateur de contenu partagé (interface) */ +typedef struct _GShareContainerIface GShareContainerIface; + + +/* Détermine le type d'une interface pour l'intégration de contenu partagé. */ +GType g_share_container_get_type(void) G_GNUC_CONST; + +/* Assure la mise à jour du contenu d'un intégrateur. */ +void g_share_container_replace(GShareContainer *, GSharedInstance *, GSharedInstance *); + + + +#endif /* _ARCH_SHARING_CONTAINER_H */ diff --git a/src/arch/sharing/instance.c b/src/arch/sharing/instance.c index b737206..956a4c7 100644 --- a/src/arch/sharing/instance.c +++ b/src/arch/sharing/instance.c @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * content.c - lecture de données binaires quelconques + * instance.c - partage de données d'architecture quelconques * * Copyright (C) 2016 Cyrille Bagard * @@ -42,7 +42,7 @@ G_DEFINE_INTERFACE(GSharedInstance, g_shared_instance, G_TYPE_OBJECT) /****************************************************************************** * * -* Paramètres : iface = interface GTK à initialiser. * +* Paramètres : iface = interface GLib à initialiser. * * * * Description : Procède à l'initialisation de l'interface de partage. * * * diff --git a/src/arch/sharing/instance.h b/src/arch/sharing/instance.h index fc7fa30..8cf8385 100644 --- a/src/arch/sharing/instance.h +++ b/src/arch/sharing/instance.h @@ -1,6 +1,6 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * content.h - prototypes pour la lecture de données binaires quelconques + * instance.h - prototypes pour le partage de données d'architecture quelconques * * Copyright (C) 2016 Cyrille Bagard * diff --git a/src/arch/sharing/manager.c b/src/arch/sharing/manager.c index 9f6ec39..2e92766 100644 --- a/src/arch/sharing/manager.c +++ b/src/arch/sharing/manager.c @@ -25,6 +25,9 @@ #include <assert.h> +#ifdef DEBUG_DUMP_STATS +# include <stdio.h> +#endif @@ -34,6 +37,7 @@ struct _GShareManager GObject parent; /* A laisser en premier */ GHashTable *table; /* Collection de partages */ + GMutex access; /* Accès à la table */ GType managed; /* Type d'instances gérées */ @@ -103,6 +107,7 @@ static void g_share_manager_class_init(GShareManagerClass *class) static void g_share_manager_init(GShareManager *manager) { + g_mutex_init(&manager->access); } @@ -122,6 +127,7 @@ static void g_share_manager_init(GShareManager *manager) static void g_share_manager_dispose(GShareManager *manager) { g_hash_table_unref(manager->table); + g_mutex_clear(&manager->access); G_OBJECT_CLASS(g_share_manager_parent_class)->dispose(G_OBJECT(manager)); @@ -190,7 +196,7 @@ GShareManager *g_share_manager_new(GType type) * * ******************************************************************************/ -GSharedInstance *g_share_manager_get(const GShareManager *manager, const void *info) +GSharedInstance *g_share_manager_get(GShareManager *manager, const void *info) { GSharedInstance *result; /* Trouvaille à retourner */ gpointer found; /* Elément correspondant ? */ @@ -204,6 +210,8 @@ GSharedInstance *g_share_manager_get(const GShareManager *manager, const void *i return g_shared_instance_compare_info(key, nfo); } + g_mutex_lock(&manager->access); + found = g_hash_table_find(manager->table, (GHRFunc)find_shared_matching_info, (void *)info); if (found == NULL) @@ -220,6 +228,7 @@ GSharedInstance *g_share_manager_get(const GShareManager *manager, const void *i else { + g_shared_instance_inc_references(result); #ifndef NDEBUG new = g_hash_table_add(manager->table, result); @@ -241,6 +250,123 @@ GSharedInstance *g_share_manager_get(const GShareManager *manager, const void *i g_shared_instance_inc_references(result); } + g_mutex_unlock(&manager->access); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : manager = gestionnaire d'instance à consulter. * +* old = ancienne instance partagée à faire évoluer. * +* info = informations à retrouver intégralement. * +* container = propriétaire de l'ancienne version à contacter. * +* * +* Description : Met à jour une instance partagée. * +* * +* Retour : Instance existante déjà partagée ou nouvellement créée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GSharedInstance *g_share_manager_update(GShareManager *manager, GSharedInstance *old, const void *info, GShareContainer *container) +{ + GSharedInstance *result; /* Nouvelle instance à renvoyer*/ + + result = g_share_manager_get(manager, info); + + if (container != NULL) + g_share_container_replace(container, old, result); + + g_share_manager_put(manager, old); + return result; } + + +/****************************************************************************** +* * +* Paramètres : manager = gestionnaire d'instance à consulter. * +* shared = instance partagée à libérer. * +* * +* Description : Abandonne un usage d'une instance partagée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_share_manager_put(GShareManager *manager, GSharedInstance *shared) +{ +#ifndef NDEBUG + gboolean found; /* Présence de partage existant*/ +#endif + + g_mutex_lock(&manager->access); + + g_shared_instance_dec_references(shared); + + if (g_shared_instance_get_references(shared) == 1) + { +#ifndef NDEBUG + found = g_hash_table_remove(manager->table, shared); + assert(found); +#else + g_hash_table_remove(manager->table, shared); +#endif + } + + g_mutex_unlock(&manager->access); + +} + + +/****************************************************************************** +* * +* Paramètres : manager = gestionnaire d'instance à consulter. * +* * +* Description : Imprime des statistiques d'utilisation du gestionnaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifdef DEBUG_DUMP_STATS +void g_share_manager_dump_stats(GShareManager *manager) +{ + unsigned int counter; /* Quantité nécessaire */ + GTypeQuery query; /* Informations sur un type */ + guint size; /* Taille de la table */ + + void count_shared_instances(const GSharedInstance *key, gpointer unused, unsigned int *c) + { + *c += g_shared_instance_get_references(key); + } + + counter = 0; + + g_mutex_lock(&manager->access); + + g_hash_table_foreach(manager->table, (GHFunc)count_shared_instances, &counter); + + size = g_hash_table_size(manager->table); + + g_mutex_unlock(&manager->access); + + g_type_query(manager->managed, &query); + + printf("%s: current = %u / %u - needed = %u / %u (size=%u, saved=%u)\n", + query.type_name, + size, size * query.instance_size, + counter, counter * query.instance_size, + query.instance_size, + (counter - size) * query.instance_size); + +} +#endif diff --git a/src/arch/sharing/manager.h b/src/arch/sharing/manager.h index 85f4b1f..0a44214 100644 --- a/src/arch/sharing/manager.h +++ b/src/arch/sharing/manager.h @@ -29,6 +29,7 @@ #include <stdbool.h> +#include "container.h" #include "instance.h" @@ -59,7 +60,18 @@ GType g_share_manager_get_type(void); GShareManager *g_share_manager_new(GType); /* Retrouve ou crée une instance partagée. */ -GSharedInstance *g_share_manager_get(const GShareManager *, const void *); +GSharedInstance *g_share_manager_get(GShareManager *, const void *); + +/* Met à jour une instance partagée. */ +GSharedInstance *g_share_manager_update(GShareManager *, GSharedInstance *, const void *, GShareContainer *); + +/* Abandonne un usage d'une instance partagée. */ +void g_share_manager_put(GShareManager *, GSharedInstance *); + +/* Imprime des statistiques d'utilisation du gestionnaire. */ +#ifdef DEBUG_DUMP_STATS +void g_share_manager_dump_stats(GShareManager *); +#endif |