Project stdui: "Simple Type Dialog User-Interface"

|
Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cthread.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Serge Lussier   *
00003  *   serge.lussier@videotron.ca   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <cthread.hxx>
00022 #include <iostream>
00023 
00024 namespace control {
00025 
00026 void *thread_start_entry(void* thread_inst)
00027 {
00028     cthread* inst = (cthread*) thread_inst;
00030     inst->run_.emit();
00031     // -------------------------------
00033     return 0l;
00034 }
00035 
00036 
00037 cthread::cthread(): sigc::trackable()
00038 {
00039 }
00040 
00041 cthread::cthread(const std::string& nameid, const sigc::slot<bool>& exec_hook): trackable()
00042 {
00043    _name = nameid;
00044     run_.connect( exec_hook );
00045 }
00046 
00047 cthread::~cthread()
00048 {
00049    std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << name() << std::endl;
00050    run_.clear();
00051    end_.clear();
00052    notify_.clear();
00053    pthread_cancel(_pthID);
00054    std::cerr << "thread exited ?" << std::endl;
00055    std::cerr << std::endl << '}' << std::endl;
00056 }
00057 
00058 
00059 
00060 
00061 
00070 bool cthread::run()
00071 {
00072     int rc = pthread_create( &_pthID, 0l, thread_start_entry, (void*)this);
00073     if(rc) return false;
00074     return true;
00075 }
00076 
00077 
00083 bool cthread::exec_delegate( const sigc::slot<bool>& exec_hook)
00084 {
00085     run_.connect( exec_hook);
00086     return true;
00087 }
00088 
00089 
00094 bool cthread::exit()
00095 {
00096    std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << "." << std::endl;
00097    // signal the end of the thread just before aborting it!
00098    if(!end_.empty()) end_.emit();
00099     pthread_cancel(_pthID);
00100     std::cerr << std::endl << '}' << std::endl;
00101 
00102    return true;
00103 }
00104 
00105 }
00106 
00107 

API Documentation Generated by:  doxygen 1.4.0
About the author | Site started with trial version of DreamWeaver MX 2004 | Finalizing with  | Contact | ©2005, Serge Lussier ( Bretzel )