From e522cf0c49c28874548ff15e86a95aac1f197617 Mon Sep 17 00:00:00 2001 From: barate Date: Tue, 25 May 2010 15:35:36 +0000 Subject: [PATCH] Fixed bug in deleteJob in BatchManager_Local --- src/Local/Batch_BatchManager_Local.cxx | 27 +++++++++++++------------- src/Local/Batch_BatchManager_Local.hxx | 1 - 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Local/Batch_BatchManager_Local.cxx b/src/Local/Batch_BatchManager_Local.cxx index f4d74a8..4e356de 100644 --- a/src/Local/Batch_BatchManager_Local.cxx +++ b/src/Local/Batch_BatchManager_Local.cxx @@ -142,12 +142,22 @@ namespace Batch { // @@@ --------> SECTION CRITIQUE <-------- @@@ pthread_mutex_lock(&_threads_mutex); - if (_threads.find(id) != _threads.end()) - thread_id = _threads[id].thread_id; + bool idFound = (_threads.find(id) != _threads.end()); + if (idFound) { + string state = _threads[id].param[STATE]; + if (state != FINISHED && state != FAILED) { + pthread_cancel(_threads[id].thread_id); + pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); + } else { + cout << "Cannot delete job " << jobid.getReference() << + ". Job is already finished." << endl; + } + } pthread_mutex_unlock(&_threads_mutex); // @@@ --------> SECTION CRITIQUE <-------- @@@ - cancel(thread_id); + if (!idFound) + throw RunTimeException(string("Job with id ") + jobid.getReference() + " does not exist"); } // Methode pour le controle des jobs : suspend un job en file d'attente @@ -255,15 +265,6 @@ namespace Batch { return running; } - // Methode de destruction d'un job - void BatchManager_Local::cancel(pthread_t thread_id) - { - pthread_mutex_lock(&_threads_mutex); - pthread_cancel(thread_id); - pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); - pthread_mutex_unlock(&_threads_mutex); - } - vector BatchManager_Local::exec_command(const Parametre & param) const { @@ -347,9 +348,9 @@ namespace Batch { // Cette fontion sera automatiquement appelee lorsqu'une demande d'annulation // sera prise en compte par pthread_testcancel() Process child; + pthread_cleanup_push(BatchManager_Local::delete_on_exit, arg); pthread_cleanup_push(BatchManager_Local::setFailedOnCancel, arg); pthread_cleanup_push(BatchManager_Local::kill_child_on_exit, static_cast (&child)); - pthread_cleanup_push(BatchManager_Local::delete_on_exit, arg); // Le code retour cumule (ORed) de tous les appels diff --git a/src/Local/Batch_BatchManager_Local.hxx b/src/Local/Batch_BatchManager_Local.hxx index 085b53f..ec14db5 100644 --- a/src/Local/Batch_BatchManager_Local.hxx +++ b/src/Local/Batch_BatchManager_Local.hxx @@ -154,7 +154,6 @@ namespace Batch { std::vector exec_command(const Parametre & param) const; private: - virtual void cancel(pthread_t thread_id); static void kill_child_on_exit(void * p_pid); static void delete_on_exit(void * arg); static void setFailedOnCancel(void * arg); -- 2.39.2