diff options
Diffstat (limited to 'src/glibext/delayed.c')
-rw-r--r-- | src/glibext/delayed.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/glibext/delayed.c b/src/glibext/delayed.c index 8f23538..92e167a 100644 --- a/src/glibext/delayed.c +++ b/src/glibext/delayed.c @@ -40,6 +40,12 @@ static void g_delayed_work_class_init(GDelayedWorkClass *); /* Initialise une instance de travail différé. */ static void g_delayed_work_init(GDelayedWork *); +/* Supprime toutes les références externes. */ +static void g_delayed_work_dispose(GDelayedWork *); + +/* Procède à la libération totale de la mémoire. */ +static void g_delayed_work_finalize(GDelayedWork *); + /* Mène l'opération programmée. */ static void g_delayed_work_process(GDelayedWork *, GtkExtStatusBar *); @@ -155,6 +161,13 @@ G_DEFINE_TYPE(GDelayedWork, g_delayed_work, G_TYPE_OBJECT); static void g_delayed_work_class_init(GDelayedWorkClass *klass) { + GObjectClass *object; /* Autre version de la classe */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_delayed_work_dispose; + object->finalize = (GObjectFinalizeFunc)g_delayed_work_finalize; + g_signal_new("work-completed", G_TYPE_DELAYED_WORK, G_SIGNAL_RUN_LAST, @@ -180,6 +193,58 @@ static void g_delayed_work_class_init(GDelayedWorkClass *klass) static void g_delayed_work_init(GDelayedWork *work) { + work->completed = false; + work->mutex = g_mutex_new(); + work->cond = g_cond_new(); + +} + + +/****************************************************************************** +* * +* Paramètres : work = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_delayed_work_dispose(GDelayedWork *work) +{ + gpointer obj_class; /* Classe parente */ + + g_mutex_free(work->mutex); + g_cond_free(work->cond); + + obj_class = g_type_class_peek_parent(G_DELAYED_WORK_GET_CLASS(work)); + + //G_OBJECT_CLASS(obj_class)->dispose(G_OBJECT(work)); + +} + + +/****************************************************************************** +* * +* Paramètres : work = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_delayed_work_finalize(GDelayedWork *work) +{ + gpointer obj_class; /* Classe parente */ + + obj_class = g_type_class_peek_parent(G_DELAYED_WORK_GET_CLASS(work)); + + //G_OBJECT_CLASS(obj_class)->finalize(G_OBJECT(work)); } @@ -203,6 +268,37 @@ static void g_delayed_work_process(GDelayedWork *work, GtkExtStatusBar *statusba g_signal_emit_by_name(work, "work-completed"); + g_mutex_lock(work->mutex); + + work->completed = true; + + g_cond_signal(work->cond); + g_mutex_unlock(work->mutex); + +} + + +/****************************************************************************** +* * +* Paramètres : work = travail à surveiller. * +* * +* Description : Attend la fin de l'exécution d'une tâche donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_delayed_work_wait_for_completion(GDelayedWork *work) +{ + g_mutex_lock(work->mutex); + + while (!work->completed) + g_cond_wait(work->cond, work->mutex); + + g_mutex_unlock(work->mutex); + } |