diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/processors.c | 63 | ||||
-rw-r--r-- | src/core/processors.h | 9 |
2 files changed, 52 insertions, 20 deletions
diff --git a/src/core/processors.c b/src/core/processors.c index e82d254..9c67a87 100644 --- a/src/core/processors.c +++ b/src/core/processors.c @@ -29,7 +29,9 @@ #include <string.h> +#include "../arch/arm/v7/core.h" #include "../arch/arm/v7/processor.h" +#include "../arch/dalvik/core.h" #include "../arch/dalvik/processor.h" #include "../arch/jvm/processor.h" @@ -42,6 +44,9 @@ typedef struct _proc_t char *name; /* Désignation humaine */ GType instance; /* Type à manipuler en interne */ + init_arch_fc init; /* Phase d'intialisation */ + exit_arch_fc exit; /* Phase de relâchement */ + } proc_t; @@ -50,7 +55,7 @@ static proc_t *_processors_definitions = NULL; static size_t _processors_definitions_count = 0; /* Verrou pour des accès atomiques */ -/* ... */ +G_LOCK_DEFINE_STATIC(_pdef_access); /* Retrouve l'enregistrement correspondant à une architecture. */ @@ -63,6 +68,8 @@ static proc_t *find_processor_by_key(const char *); * Paramètres : key = désignation rapide et interne d'un processeur. * * name = désignation humaine de l'architecture. * * instance = type GLib représentant le type à instancier. * +* init = procédure d'initialisation de mécanismes internes.* +* exit = procédure de suppression de mécanismes internes. * * * * Description : Enregistre un processeur pour une architecture donnée. * * * @@ -72,26 +79,38 @@ static proc_t *find_processor_by_key(const char *); * * ******************************************************************************/ -bool register_processor_type(const char *key, const char *name, GType instance) +bool register_processor_type(const char *key, const char *name, GType instance, init_arch_fc init, exit_arch_fc exit) { + bool result; /* Bilan à retourner */ proc_t *new; /* Nouvel élément à définir */ - /* TODO : if find()... -> unref(), ret false */ + G_LOCK(_pdef_access); + + new = find_processor_by_key(key); + + result = (new == NULL); + + result &= init(); + + if (result) + { + _processors_definitions = (proc_t *)realloc(_processors_definitions, + ++_processors_definitions_count * sizeof(proc_t)); - /* TODO : lock */ + new = &_processors_definitions[_processors_definitions_count - 1]; - _processors_definitions = (proc_t *)realloc(_processors_definitions, - ++_processors_definitions_count * sizeof(proc_t)); + new->key = strdup(key); + new->name = strdup(name); + new->instance = instance; - new = &_processors_definitions[_processors_definitions_count - 1]; + new->init = init; + new->exit = exit; - new->key = strdup(key); - new->name = strdup(name); - new->instance = instance; + } - /* TODO : unlock */ + G_UNLOCK(_pdef_access); - return true; + return result; } @@ -114,9 +133,11 @@ bool load_hard_coded_processors_definitions(void) result = true; - result &= register_processor_type("armv7", "ARM v7", G_TYPE_ARMV7_PROCESSOR); + result &= register_processor_type("armv7", "ARM v7", G_TYPE_ARMV7_PROCESSOR, + init_armv7_core, exit_armv7_core); - result &= register_processor_type("dalvik", "Dalvik Virtual Machine", G_TYPE_DALVIK_PROCESSOR); + result &= register_processor_type("dalvik", "Dalvik Virtual Machine", G_TYPE_DALVIK_PROCESSOR, + init_dalvik_core, exit_dalvik_core); //result &= register_processor_type("jvm", "Java Virtual Machine", G_TYPE_JVM_PROCESSOR); @@ -141,6 +162,8 @@ void unload_processors_definitions(void) { size_t i; /* Boucle de parcours */ + G_LOCK(_pdef_access); + for (i = 0; i < _processors_definitions_count; i++) { free(_processors_definitions[i].key); @@ -153,6 +176,8 @@ void unload_processors_definitions(void) _processors_definitions = NULL; _processors_definitions_count = 0; + G_UNLOCK(_pdef_access); + } @@ -206,7 +231,7 @@ const char *get_arch_processor_name(const char *key) const char *result; /* Description à retourner */ proc_t *def; /* Définition d'architecture */ - /* TODO : lock */ + G_LOCK(_pdef_access); def = find_processor_by_key(key); @@ -214,8 +239,8 @@ const char *get_arch_processor_name(const char *key) result = NULL; else result = def->name; - - /* TODO : unlock */ + + G_UNLOCK(_pdef_access); return result; @@ -239,7 +264,7 @@ GArchProcessor *get_arch_processor_for_type(const char *key) GArchProcessor *result; /* Instance à retourner */ proc_t *def; /* Définition d'architecture */ - /* TODO : lock */ + G_LOCK(_pdef_access); def = find_processor_by_key(key); @@ -248,7 +273,7 @@ GArchProcessor *get_arch_processor_for_type(const char *key) else result = g_object_new(def->instance, NULL); - /* TODO : unlock */ + G_UNLOCK(_pdef_access); return result; diff --git a/src/core/processors.h b/src/core/processors.h index b2e9cd5..4f82dc3 100644 --- a/src/core/processors.h +++ b/src/core/processors.h @@ -33,8 +33,15 @@ +/* Mise en place de mécanismes internes */ +typedef bool (* init_arch_fc) (void); + +/* Suppression de mécanismes internes */ +typedef void (* exit_arch_fc) (void); + + /* Enregistre un processeur pour une architecture donnée. */ -bool register_processor_type(const char *, const char *, GType); +bool register_processor_type(const char *, const char *, GType, init_arch_fc, exit_arch_fc); /* Charge les définitions de processeurs "natifs". */ bool load_hard_coded_processors_definitions(void); |