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
00027 #include "ArExport.h"
00028
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
00068
00069
00070
00071
00072
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