- Main Page
- Namespaces
- Classes
- Files

- Search for |

# thread.cpp

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 // "thread.cpp"
    00004
    00005 // (c) OPAC Team, LIFL, August 2005
    00006
    00007 /* This library is free software; you can redistribute it and/or
    00008    modify it under the terms of the GNU Lesser General Public
    00009    License as published by the Free Software Foundation; either
    00010    version 2 of the License, or (at your option) any later version.
    00011
    00012    This library is distributed in the hope that it will be useful,
    00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015    Lesser General Public License for more details.
    00016
    00017    You should have received a copy of the GNU Lesser General Public
    00018    License along with this library; if not, write to the Free Software
    00019    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    00020
    00021    Contact: paradiseo-help@lists.gforge.inria.fr
    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   /* Nothing ! */
    00041 }
    00042
    00043 extern int getNodeRank ();
    00044
    00045 void Thread :: setActive () {
    00046
    00047   if (! act ) {
    00048
    00049     act = true;
    00050     num_act ++;
    00051     //    if (getNodeRank () == 1)
    00052     //   printf ("On passe a %d\n", num_act);
    00053   }
    00054 }
    00055
    00056 void Thread :: setPassive () {
    00057
    00058   if (act) {
    00059
    00060    act = false;
    00061     num_act --;
    00062     //    if (getNodeRank () == 1)
    00063     //  printf ("On passe a %d\n", num_act);
    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 }