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

ArThread.cpp

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
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 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #include "ArExport.h"
00028 // ArThread.cc -- Thread classes
00029 
00030 
00031 #include "ariaOSDef.h"
00032 #include <errno.h>
00033 #include <list>
00034 #include "ArThread.h"
00035 #include "ArLog.h"
00036 
00037 
00038 ArMutex ArThread::ourThreadsMutex;
00039 ArThread::MapType ArThread::ourThreads;
00040 ArLog::LogLevel ArThread::ourLogLevel = ArLog::Verbose;
00041 
00042 void ArThread::stopAll()
00043 {
00044   MapType::iterator iter;
00045 
00046   ourThreadsMutex.lock();
00047   for (iter=ourThreads.begin(); iter != ourThreads.end(); ++iter)
00048     (*iter).second->stopRunning();
00049   ourThreadsMutex.unlock();
00050 }
00051 
00052 void ArThread::joinAll()
00053 {
00054   MapType::iterator iter;
00055   ArThread *thread;
00056 
00057   thread=self();
00058   ourThreadsMutex.lock();
00059   for (iter=ourThreads.begin(); iter != ourThreads.end(); ++iter)
00060   {
00061     if ((*iter).second->getJoinable() && thread && (thread != (*iter).second))
00062     {
00063       (*iter).second->doJoin();
00064     }
00065   }
00066   ourThreads.clear();
00067   // MPL BUG I'm not to sure why this insert was here, as far as I can
00068   // tell all it would do is make it so you could join the threads
00069   // then start them all up again, but I don't see much utility in
00070   // that so I'm not going to worry about it now
00071  
00072   //ourThreads.insert(MapType::value_type(thread->myThread, thread));
00073   ourThreadsMutex.unlock();
00074 }
00075 
00076 ArThread::ArThread(bool blockAllSignals) :
00077   myRunning(false),
00078   myJoinable(false),
00079   myBlockAllSignals(blockAllSignals),
00080   myFunc(0),
00081   myThread(),
00082   myStrMap()
00083 {
00084 }
00085 
00086 ArThread::ArThread(ThreadType thread, bool joinable,
00087                             bool blockAllSignals) :
00088   myRunning(false),
00089   myJoinable(joinable),
00090   myBlockAllSignals(blockAllSignals),
00091   myFunc(0),
00092   myThread(thread),
00093   myStrMap()
00094 {
00095 }
00096 
00097 ArThread::ArThread(ArFunctor *func, bool joinable,
00098                             bool blockAllSignals) :
00099   myRunning(false),
00100   myJoinable(false),
00101   myBlockAllSignals(blockAllSignals),
00102   myFunc(func),
00103   myThread(),
00104   myStrMap()
00105 {
00106   create(func, joinable);
00107 }
00108 
00109 ArThread::~ArThread()
00110 {
00111 }
00112 
00113 int ArThread::join(void **iret)
00114 {
00115   int ret;
00116   ret=doJoin(iret);
00117   if (ret)
00118     return(ret);
00119 
00120   ourThreadsMutex.lock();
00121   ourThreads.erase(myThread);
00122   ourThreadsMutex.unlock();
00123 
00124   return(0);
00125 }
00126 
00127 

Generated on Wed Oct 19 12:56:37 2005 for Aria by  doxygen 1.4.0