X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/b92547a5de3a3fb4f14a2bea4a4e776b8da3cb5c..dafb509182bac9b314202fe7dfaf58206da5ccbe:/Server/src/runnable.cpp?ds=sidebyside diff --git a/Server/src/runnable.cpp b/Server/src/runnable.cpp index 0439ca0..6d000ce 100644 --- a/Server/src/runnable.cpp +++ b/Server/src/runnable.cpp @@ -26,7 +26,7 @@ // #include "plaqui/server/runnable.h" -#include +#include #include #ifdef DEBUG # include @@ -40,38 +40,41 @@ namespace Server { Runnable::~Runnable(void) { #ifdef DEBUG - cerr << __FILE__ << ": destructor(this = " << this << ")" - << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": destructor(this = " << this << ")." << endl; #endif // DEBUG } -Runnable::Runnable(void): thread(0), stop(false) { +Runnable::Runnable(void): _thread(NULL), _stop(false) { #ifdef DEBUG - cerr << __FILE__ << ": constructor." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": constructor(this = " << this << ")." << endl; #endif // DEBUG } void Runnable::static_run(Runnable* runner) { #ifdef DEBUG - cerr << __FILE__ << ": static_run(runner = " << runner << ")" - << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": static_run(runner = " << runner << ")" << endl; #endif // DEBUG + // Corre tarea. runner->real_run(); - runner->signal_finished().emit(); + // Manda señal de tarea finalizada + runner->_finished(); delete runner; } void Runnable::run(bool detach) { #ifdef DEBUG - cerr << __FILE__ << ": run(detach = " << detach << ")" << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": run(detach = " << detach << ")" << endl; #endif // DEBUG // Si vamos a correr la tarea en un thread. if (detach) { // Corremos el thread en una funcion estática para poder destruirlo al // finalizar, pasandole el puntero al objeto. - thread = Glib::Thread::create( - SigC::bind(SigC::slot(&Runnable::static_run), this), - true); + _thread = Glib::Thread::create( + SigC::bind(SigC::slot(&Runnable::static_run), this), false); // Si no corremos la tarea normalmente. } else { real_run(); @@ -79,18 +82,33 @@ void Runnable::run(bool detach) { } -void Runnable::finish(bool attach) { +void Runnable::finish(void) { #ifdef DEBUG - cerr << __FILE__ << ": finish(attach = " << attach << ")" << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": finish();" << endl; #endif // DEBUG - stop = true; - if (attach) { - thread->join(); - } + stop(true); +} + +bool Runnable::stop(void) { + Glib::Mutex::Lock lock(stop_mutex); + bool tmp = _stop; + return tmp; +} + +bool Runnable::stop(bool stop) { + Glib::Mutex::Lock lock(stop_mutex); + bool tmp = _stop; + _stop = stop; + return tmp; } Runnable::SignalFinished& Runnable::signal_finished(void) { - return finished; + return _finished; +} + +Runnable::SignalError& Runnable::signal_error(void) { + return _error; } } // namespace Server