00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "ArExport.h"
00027
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;
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
00067
00068
00069
00070
00071
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