Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArThread.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "ArExport.h"
00027 // ArThread.cc -- Thread classes
00028 
00029 
00030 #include "ariaOSDef.h"
00031 #include <errno.h>
00032 #include <list>
00033 #include "ArThread.h"
00034 #include "ArLog.h"
00035 
00036 
00037 ArMutex ArThread::ourThreadsMutex;
00038 ArThread::MapType ArThread::ourThreads;
00039 AREXPORT ArLog::LogLevel ArThread::ourLogLevel = ArLog::Verbose; // todo, instead of AREXPORT move accessors into .cpp?
00040 
00041 AREXPORT void ArThread::stopAll()
00042 {
00043   MapType::iterator iter;
00044 
00045   ourThreadsMutex.lock();
00046   for (iter=ourThreads.begin(); iter != ourThreads.end(); ++iter)
00047     (*iter).second->stopRunning();
00048   ourThreadsMutex.unlock();
00049 }
00050 
00051 AREXPORT void ArThread::joinAll()
00052 {
00053   MapType::iterator iter;
00054   ArThread *thread;
00055 
00056   thread=self();
00057   ourThreadsMutex.lock();
00058   for (iter=ourThreads.begin(); iter != ourThreads.end(); ++iter)
00059   {
00060     if ((*iter).second->getJoinable() && thread && (thread != (*iter).second))
00061     {
00062       (*iter).second->doJoin();
00063     }
00064   }
00065   ourThreads.clear();
00066   // MPL BUG I'm not to sure why this insert was here, as far as I can
00067   // tell all it would do is make it so you could join the threads
00068   // then start them all up again, but I don't see much utility in
00069   // that so I'm not going to worry about it now
00070  
00071   //ourThreads.insert(MapType::value_type(thread->myThread, thread));
00072   ourThreadsMutex.unlock();
00073 }
00074 
00075 AREXPORT ArThread::ArThread(bool blockAllSignals) :
00076   myRunning(false),
00077   myJoinable(false),
00078   myBlockAllSignals(blockAllSignals),
00079   myFunc(0),
00080   myThread(),
00081   myStrMap()
00082 {
00083 }
00084 
00085 AREXPORT ArThread::ArThread(ThreadType thread, bool joinable,
00086                 bool blockAllSignals) :
00087   myRunning(false),
00088   myJoinable(joinable),
00089   myBlockAllSignals(blockAllSignals),
00090   myFunc(0),
00091   myThread(thread),
00092   myStrMap()
00093 {
00094 }
00095 
00096 AREXPORT ArThread::ArThread(ArFunctor *func, bool joinable,
00097                 bool blockAllSignals) :
00098   myRunning(false),
00099   myJoinable(false),
00100   myBlockAllSignals(blockAllSignals),
00101   myFunc(func),
00102   myThread(),
00103   myStrMap()
00104 {
00105   create(func, joinable);
00106 }
00107 
00108 AREXPORT ArThread::~ArThread()
00109 {
00110 }
00111 
00112 AREXPORT int ArThread::join(void **iret)
00113 {
00114   int ret;
00115   ret=doJoin(iret);
00116   if (ret)
00117     return(ret);
00118 
00119   ourThreadsMutex.lock();
00120   ourThreads.erase(myThread);
00121   ourThreadsMutex.unlock();
00122 
00123   return(0);
00124 }
00125 
00126 

Generated on Tue Feb 20 10:51:41 2007 for Aria by  doxygen 1.4.0