- Main Page
- Namespaces
- Classes
- Files

- Search for |

# thread.cpp

    00001 // "thread.cpp"
    00002
    00003 // (c) OPAC Team, LIFL, August 2005
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #include <map>
    00010
    00011 #include "thread.h"
    00012
    00013 static std :: vector <Thread *> threads;
    00014
    00015 unsigned num_act = 0;
    00016
    00017 Thread :: Thread () {
    00018
    00019   threads.push_back (this);
    00020   act = false;
    00021 }
    00022
    00023 Thread :: ~ Thread () {
    00024
    00025   /* Nothing ! */
    00026 }
    00027
    00028 extern int getNodeRank ();
    00029
    00030 void Thread :: setActive () {
    00031
    00032   if (! act ) {
    00033
    00034     act = true;
    00035     num_act ++;
    00036     //    if (getNodeRank () == 1)
    00037     //   printf ("On passe a %d\n", num_act);
    00038   }
    00039 }
    00040
    00041 void Thread :: setPassive () {
    00042
    00043   if (act) {
    00044
    00045    act = false;
    00046     num_act --;
    00047     //    if (getNodeRank () == 1)
    00048     //  printf ("On passe a %d\n", num_act);
    00049
    00050   }
    00051 }
    00052
    00053 bool atLeastOneActiveThread () {
    00054
    00055   return num_act;
    00056 }
    00057
    00058 unsigned numberOfActiveThreads () {
    00059
    00060   return num_act;
    00061 }
    00062
    00063 static void * launch (void * __arg) {
    00064
    00065   Thread * thr = (Thread *) __arg;
    00066   thr -> start ();
    00067   return 0;
    00068 }
    00069
    00070 void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) {
    00071
    00072   pthread_t * ll_thr = new pthread_t;
    00073   __ll_threads.push_back (ll_thr);
    00074   pthread_create (ll_thr, 0, launch, __hl_thread);
    00075 }
    00076
    00077 void joinThreads (std :: vector <pthread_t *> & __threads) {
    00078
    00079   for (unsigned i = 0; i < __threads.size (); i ++)
    00080     pthread_join (* __threads [i], 0);
    00081 }