00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <map>
00025
00026 #include "thread.h"
00027
00028 static std :: vector <Thread *> threads;
00029
00030 unsigned num_act = 0;
00031
00032 Thread :: Thread () {
00033
00034 threads.push_back (this);
00035 act = false;
00036 }
00037
00038 Thread :: ~ Thread () {
00039
00040
00041 }
00042
00043 extern int getNodeRank ();
00044
00045 void Thread :: setActive () {
00046
00047 if (! act ) {
00048
00049 act = true;
00050 num_act ++;
00051
00052
00053 }
00054 }
00055
00056 void Thread :: setPassive () {
00057
00058 if (act) {
00059
00060 act = false;
00061 num_act --;
00062
00063
00064
00065 }
00066 }
00067
00068 bool atLeastOneActiveThread () {
00069
00070 return num_act;
00071 }
00072
00073 unsigned numberOfActiveThreads () {
00074
00075 return num_act;
00076 }
00077
00078 static void * launch (void * __arg) {
00079
00080 Thread * thr = (Thread *) __arg;
00081 thr -> start ();
00082 return 0;
00083 }
00084
00085 void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) {
00086
00087 pthread_t * ll_thr = new pthread_t;
00088 __ll_threads.push_back (ll_thr);
00089 pthread_create (ll_thr, 0, launch, __hl_thread);
00090 }
00091
00092 void joinThreads (std :: vector <pthread_t *> & __threads) {
00093
00094 for (unsigned i = 0; i < __threads.size (); i ++)
00095 pthread_join (* __threads [i], 0);
00096 }