X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/7e74b790d290cd7d776349503bb361c47933c01f..6f70c17ffefd6150b68ac0f64a8116e730437408:/Server/src/runnable.cpp diff --git a/Server/src/runnable.cpp b/Server/src/runnable.cpp index c134b83..9587fd9 100644 --- a/Server/src/runnable.cpp +++ b/Server/src/runnable.cpp @@ -41,26 +41,26 @@ namespace Server { Runnable::~Runnable(void) { #ifdef DEBUG cerr << __FILE__ << "(" << __LINE__ << ")" - << ": destructor(this = " << this << ")" - << endl; + << ": destructor(this = " << this << ")." << endl; #endif // DEBUG } -Runnable::Runnable(void): thread(0), stop(false) { +Runnable::Runnable(void): _thread(NULL), _stop(false) { #ifdef DEBUG cerr << __FILE__ << "(" << __LINE__ << ")" - << ": constructor." << endl; + << ": constructor(this = " << this << ")." << endl; #endif // DEBUG } void Runnable::static_run(Runnable* runner) { #ifdef DEBUG cerr << __FILE__ << "(" << __LINE__ << ")" - << ": static_run(runner = " << runner << ")" - << endl; + << ": static_run(runner = " << runner << ")" << endl; #endif // DEBUG + // Corre tarea. runner->real_run(); - runner->finished(); + // Manda señal de tarea finalizada + runner->_finished(); delete runner; } @@ -73,9 +73,9 @@ void Runnable::run(bool detach) { if (detach) { // Corremos el thread en una funcion estática para poder destruirlo al // finalizar, pasandole el puntero al objeto. - thread = Glib::Thread::create( + _thread = Glib::Thread::create( SigC::bind(SigC::slot(&Runnable::static_run), this), - true); + false); // Si no corremos la tarea normalmente. } else { real_run(); @@ -83,23 +83,33 @@ void Runnable::run(bool detach) { } -void Runnable::finish(bool attach) { +void Runnable::finish(void) { #ifdef DEBUG cerr << __FILE__ << "(" << __LINE__ << ")" - << ": finish(attach = " << attach << ")" << endl; + << ": 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; + return _error; } } // namespace Server