diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-06-01 18:57:41 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-06-01 18:57:41 (GMT) |
commit | e060d9a9f29c0d7708e7002c2e1fc4962020ba94 (patch) | |
tree | f2049553e452a420c2804c68e8e84aff678634a0 /src/core | |
parent | c023fa77f9765c6c80793003a5c4fbf8d5a4bd5a (diff) |
Improved the way threads are managed.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/queue.c | 107 | ||||
-rw-r--r-- | src/core/queue.h | 11 |
2 files changed, 103 insertions, 15 deletions
diff --git a/src/core/queue.c b/src/core/queue.c index 4439e61..9323803 100644 --- a/src/core/queue.c +++ b/src/core/queue.c @@ -25,12 +25,19 @@ #include <assert.h> +#include <malloc.h> #include "global.h" +/* Mémorisation des groupes de travail */ +static wgroup_id_t *_global_group_ids = NULL; +static size_t _global_group_count = 0; +G_LOCK_DEFINE_STATIC(_gg_mutex); + + /****************************************************************************** * * * Paramètres : - * @@ -54,24 +61,24 @@ bool init_global_works(void) set_work_queue(queue); #ifndef NDEBUG - expected = g_work_queue_define_work_group(queue); + expected = setup_global_work_group(); assert(expected == DEFAULT_WORK_GROUP); #else - g_work_queue_define_work_group(queue); + setup_global_work_group(); #endif #ifndef NDEBUG - expected = g_work_queue_define_work_group(queue); + expected = setup_global_work_group(); assert(expected == LOADING_WORK_GROUP); #else - g_work_queue_define_work_group(queue); + setup_global_work_group(); #endif #ifndef NDEBUG - expected = g_work_queue_define_work_group(queue); + expected = setup_global_work_group(); assert(expected == STORAGE_WORK_GROUP); #else - g_work_queue_define_work_group(queue); + setup_global_work_group(); #endif return true; @@ -83,6 +90,76 @@ bool init_global_works(void) * * * Paramètres : - * * * +* Description : Constitue un nouveau groupe de travail global. * +* * +* Retour : Nouvel identifiant unique d'un nouveau groupe de travail. * +* * +* Remarques : - * +* * +******************************************************************************/ + +wgroup_id_t setup_global_work_group(void) +{ + wgroup_id_t result; /* Valeur à retourner */ + GWorkQueue *queue; /* Singleton pour tâches */ + + queue = get_work_queue(); + + result = g_work_queue_define_work_group(queue); + + G_LOCK(_gg_mutex); + + _global_group_ids = (wgroup_id_t *)realloc(_global_group_ids, + ++_global_group_count * sizeof(wgroup_id_t)); + + _global_group_ids[_global_group_count - 1] = result; + + G_UNLOCK(_gg_mutex); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : count = quantité de threads à allouer. * +* * +* Description : Constitue un nouveau petit groupe de travail global. * +* * +* Retour : Nouvel identifiant unique d'un nouveau groupe de travail. * +* * +* Remarques : - * +* * +******************************************************************************/ + +wgroup_id_t setup_tiny_global_work_group(guint count) +{ + wgroup_id_t result; /* Valeur à retourner */ + GWorkQueue *queue; /* Singleton pour tâches */ + + queue = get_work_queue(); + + result = g_work_queue_define_tiny_work_group(queue, count); + + G_LOCK(_gg_mutex); + + _global_group_ids = (wgroup_id_t *)realloc(_global_group_ids, + ++_global_group_count * sizeof(wgroup_id_t)); + + _global_group_ids[_global_group_count - 1] = result; + + G_UNLOCK(_gg_mutex); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * * Description : Supprime les mécanismes de traitements parallèles. * * * * Retour : - * @@ -95,6 +172,16 @@ void exit_global_works(void) { GWorkQueue *queue; /* Singleton pour tâches */ + G_LOCK(_gg_mutex); + + if (_global_group_ids != NULL) + free(_global_group_ids); + + _global_group_ids = NULL; + _global_group_count = 0; + + G_UNLOCK(_gg_mutex); + queue = get_work_queue(); g_object_unref(G_OBJECT(queue)); @@ -118,14 +205,8 @@ void wait_for_all_global_works(void) { GWorkQueue *queue; /* Singleton pour tâches */ - static const wgroup_id_t group_ids[GLOBAL_WORK_GROUPS_COUNT] = { - DEFAULT_WORK_GROUP, - LOADING_WORK_GROUP, - STORAGE_WORK_GROUP - }; - queue = get_work_queue(); - g_work_queue_wait_for_all_completions(queue, group_ids, GLOBAL_WORK_GROUPS_COUNT); + g_work_queue_wait_for_all_completions(queue, _global_group_ids, _global_group_count); } diff --git a/src/core/queue.h b/src/core/queue.h index a1b82f2..8f1625e 100644 --- a/src/core/queue.h +++ b/src/core/queue.h @@ -28,6 +28,9 @@ #include <stdbool.h> +#include "../glibext/delayed.h" + + /** * Groupes d'exécution principaux. @@ -37,12 +40,16 @@ #define LOADING_WORK_GROUP 1 #define STORAGE_WORK_GROUP 2 -#define GLOBAL_WORK_GROUPS_COUNT 3 - /* Met en place les mécanismes de traitements parallèles. */ bool init_global_works(void); +/* Constitue un nouveau groupe de travail global. */ +wgroup_id_t setup_global_work_group(void); + +/* Constitue un nouveau petit groupe de travail global. */ +wgroup_id_t setup_tiny_global_work_group(guint); + /* Supprime les mécanismes de traitements parallèles. */ void exit_global_works(void); |