diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2016-10-09 11:57:58 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2016-10-09 11:57:58 (GMT) | 
| commit | 0b6e87de0d4313f8ef31907bc48ce4d7f7749738 (patch) | |
| tree | f268e98efa733379b275d8834864f13cff6fa9ac /src/format/dex/pool.c | |
| parent | 3628caa2311ee89ad0d2a0aa2438d7e85b497da4 (diff) | |
Loaded all Dex pool items using several threads.
Diffstat (limited to 'src/format/dex/pool.c')
| -rw-r--r-- | src/format/dex/pool.c | 120 | 
1 files changed, 92 insertions, 28 deletions
diff --git a/src/format/dex/pool.c b/src/format/dex/pool.c index 7574638..769a4f1 100644 --- a/src/format/dex/pool.c +++ b/src/format/dex/pool.c @@ -32,6 +32,7 @@  #include "dex-int.h" +#include "loading.h"  #include "../mangling/demangler.h"  #include "../mangling/dex/context.h" @@ -125,6 +126,7 @@ const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index)  /******************************************************************************  *                                                                             *  *  Paramètres  : format = description de l'exécutable à compléter.            * +*                gid    = groupe de travail impliqué.                         *                   status = barre de statut à tenir informée.                   *  *                                                                             *  *  Description : Charge en mémoire l'ensemble des types du format DEX.        * @@ -135,33 +137,53 @@ const char *get_string_from_dex_pool(const GDexFormat *format, uint32_t index)  *                                                                             *  ******************************************************************************/ -bool load_all_dex_types(GDexFormat *format, GtkStatusStack *status) +bool load_all_dex_types(GDexFormat *format, wgroup_id_t gid, GtkStatusStack *status)  {      bool result;                            /* Bilan à retourner           */ +    guint runs_count;                       /* Qté d'exécutions parallèles */ +    uint32_t run_size;                      /* Volume réparti par exécution*/ +    GWorkQueue *queue;                      /* Gestionnaire de différés    */      activity_id_t msg;                      /* Message de progression      */ -    uint32_t i;                             /* Boucle de parcours          */ -    GDataType *type;                        /* Type récupéré               */ +    guint i;                                /* Boucle de parcours          */ +    uint32_t begin;                         /* Début de bloc de traitement */ +    uint32_t end;                           /* Fin d'un bloc de traitement */ +    GDexLoading *loading;                   /* Tâche de chargement à lancer*/      result = true; +    /* Préparation du réceptacle */ +      format->types = (GDataType **)calloc(format->header.type_ids_size, sizeof(GDataType *)); +    /* Lancement des chargements */ + +    runs_count = g_get_num_processors(); + +    run_size = format->header.type_ids_size / runs_count; + +    queue = get_work_queue(); +      msg = gtk_status_stack_add_activity(status, _("Loading all types from the Dex pool..."),                                          format->header.type_ids_size); -    for (i = 0; i < format->header.type_ids_size && result; i++) +    for (i = 0; i < runs_count; i++)      { -        type = get_type_from_dex_pool(format, i); +        begin = i * run_size; -        if (type != NULL) -            g_object_unref(G_OBJECT(type)); +        if ((i + 1) == runs_count) +            end = format->header.type_ids_size;          else -            result = false; +            end = begin + run_size; + +        loading = g_dex_loading_new(format, begin, end, msg, +                                    (dex_loading_cb)get_type_from_dex_pool, &result); -        gtk_status_stack_update_activity_value(status, msg, 1); +        g_work_queue_schedule_work(queue, G_DELAYED_WORK(loading), gid);      } +    g_work_queue_wait_for_completion(queue, gid); +      gtk_status_stack_remove_activity(status, msg);      return result; @@ -235,6 +257,7 @@ GDataType *get_type_from_dex_pool(GDexFormat *format, uint32_t index)  /******************************************************************************  *                                                                             *  *  Paramètres  : format = description de l'exécutable à compléter.            * +*                gid    = groupe de travail impliqué.                         *  *                status = barre de statut à tenir informée.                   *  *                                                                             *  *  Description : Charge en mémoire l'ensemble des champs du format DEX.       * @@ -245,33 +268,53 @@ GDataType *get_type_from_dex_pool(GDexFormat *format, uint32_t index)  *                                                                             *  ******************************************************************************/ -bool load_all_dex_fields(GDexFormat *format, GtkStatusStack *status) +bool load_all_dex_fields(GDexFormat *format, wgroup_id_t gid, GtkStatusStack *status)  {      bool result;                            /* Bilan à retourner           */ +    guint runs_count;                       /* Qté d'exécutions parallèles */ +    uint32_t run_size;                      /* Volume réparti par exécution*/ +    GWorkQueue *queue;                      /* Gestionnaire de différés    */      activity_id_t msg;                      /* Message de progression      */ -    uint32_t i;                             /* Boucle de parcours          */ -    GBinVariable *field;                    /* Champ récupéré              */ +    guint i;                                /* Boucle de parcours          */ +    uint32_t begin;                         /* Début de bloc de traitement */ +    uint32_t end;                           /* Fin d'un bloc de traitement */ +    GDexLoading *loading;                   /* Tâche de chargement à lancer*/      result = true; +    /* Préparation du réceptacle */ +      format->fields = (GBinVariable **)calloc(format->header.field_ids_size, sizeof(GBinVariable *)); +    /* Lancement des chargements */ + +    runs_count = g_get_num_processors(); + +    run_size = format->header.field_ids_size / runs_count; + +    queue = get_work_queue(); +      msg = gtk_status_stack_add_activity(status, _("Loading all fields from the Dex pool..."),                                          format->header.field_ids_size); -    for (i = 0; i < format->header.field_ids_size && result; i++) +    for (i = 0; i < runs_count; i++)      { -        field = get_field_from_dex_pool(format, i); +        begin = i * run_size; -        if (field != NULL) -            g_object_unref(G_OBJECT(field)); +        if ((i + 1) == runs_count) +            end = format->header.field_ids_size;          else -            result = false; +            end = begin + run_size; + +        loading = g_dex_loading_new(format, begin, end, msg, +                                    (dex_loading_cb)get_field_from_dex_pool, &result); -        gtk_status_stack_update_activity_value(status, msg, 1); +        g_work_queue_schedule_work(queue, G_DELAYED_WORK(loading), gid);      } +    g_work_queue_wait_for_completion(queue, gid); +      gtk_status_stack_remove_activity(status, msg);      return result; @@ -506,7 +549,8 @@ GDexMethod *get_method_from_dex_pool(GDexFormat *format, uint32_t index)  /******************************************************************************  *                                                                             *  *  Paramètres  : format = représentation interne du format DEX à compléter.   * -*                status = barre de statut à tenir informée.                   * +*                gid    = groupe de travail impliqué.                         * +                 status = barre de statut à tenir informée.                   *  *                                                                             *  *  Description : Charge toutes les classes listées dans le contenu binaire.   *  *                                                                             * @@ -516,33 +560,53 @@ GDexMethod *get_method_from_dex_pool(GDexFormat *format, uint32_t index)  *                                                                             *  ******************************************************************************/ -bool load_all_dex_classes(GDexFormat *format, GtkStatusStack *status) +bool load_all_dex_classes(GDexFormat *format, wgroup_id_t gid, GtkStatusStack *status)  {      bool result;                            /* Bilan à retourner           */ +    guint runs_count;                       /* Qté d'exécutions parallèles */ +    uint32_t run_size;                      /* Volume réparti par exécution*/ +    GWorkQueue *queue;                      /* Gestionnaire de différés    */      activity_id_t msg;                      /* Message de progression      */ -    uint32_t i;                             /* Boucle de parcours          */ -    GDexClass *class;                       /* Classe récupérée            */ +    guint i;                                /* Boucle de parcours          */ +    uint32_t begin;                         /* Début de bloc de traitement */ +    uint32_t end;                           /* Fin d'un bloc de traitement */ +    GDexLoading *loading;                   /* Tâche de chargement à lancer*/      result = true; +    /* Préparation du réceptacle */ +      format->classes = (GDexClass **)calloc(format->header.class_defs_size, sizeof(GDexClass *)); +    /* Lancement des chargements */ + +    runs_count = g_get_num_processors(); + +    run_size = format->header.class_defs_size / runs_count; + +    queue = get_work_queue(); +      msg = gtk_status_stack_add_activity(status, _("Loading all classes from the Dex pool..."),                                          format->header.class_defs_size); -    for (i = 0; i < format->header.class_defs_size && result; i++) +    for (i = 0; i < runs_count; i++)      { -        class = get_class_from_dex_pool(format, i); +        begin = i * run_size; -        if (class != NULL) -            g_object_unref(G_OBJECT(class)); +        if ((i + 1) == runs_count) +            end = format->header.class_defs_size;          else -            result = false; +            end = begin + run_size; + +        loading = g_dex_loading_new(format, begin, end, msg, +                                    (dex_loading_cb)get_class_from_dex_pool, &result); -        gtk_status_stack_update_activity_value(status, msg, 1); +        g_work_queue_schedule_work(queue, G_DELAYED_WORK(loading), gid);      } +    g_work_queue_wait_for_completion(queue, gid); +      gtk_status_stack_remove_activity(status, msg);      return result;  | 
