root/juggler/tags/1.0.5/Threads/vjThreadManager.cpp

Revision 3417, 3.4 kB (checked in by patrickh, 8 years ago)

Merged the RELENG_0_2 branch into RELENG_1_0. RELENG_0_2 is now considered
a dead branch as we a pushing forward with a 1.0 release instead of a 0.2
beta release. Woo hoo!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  * -----------------------------------------------------------------
26  * File:          $RCSfile$
27  * Date modified: $Date$
28  * Version:       $Revision$
29  * -----------------------------------------------------------------
30  *
31  *************** <auto-copyright.pl END do not edit this line> ***************/
32
33
34 #include <vjConfig.h>
35 #include <Threads/vjThreadManager.h>
36 #include <Kernel/vjDebug.h>
37
38 //vjThreadManager* vjThreadManager::_instance = NULL;
39 vjSingletonImp(vjThreadManager);
40
41
42 //-----------------------------------------------------
43 //: Called when a thread has been added to the system.
44 //
45 //! PRE: Manager must be locked.
46 //-----------------------------------------------------
47 void vjThreadManager::addThread(vjBaseThread* thread)
48 {
49    vjASSERT(mThreadVectorMutex.test()==1); // Assert manager locked
50    vjASSERT(thread->getTID() >= 0);
51
52    // Insert thread into local table
53    while ((int)mThreads.size() <= thread->getTID())
54       mThreads.push_back(NULL);
55    mThreads[thread->getTID()] = thread;
56
57    debugDump();               // Dump current state
58 }
59
60 //-----------------------------------------------------
61 //: Called when a thread has been removed from the
62 //+ system.
63 //
64 //! PRE: Manager must be locked.
65 //-----------------------------------------------------
66 void vjThreadManager::removeThread(vjBaseThread* thread)
67 {
68    vjASSERT(mThreadVectorMutex.test()==1); // Assert manager locked
69    vjASSERT((thread->getTID() >= 0) && (thread->getTID() < (int)mThreads.size()));
70    mThreads[(unsigned int)thread->getTID()] = NULL;
71 }
72
73
74 //: Dump the state of the manager to debug
75 void vjThreadManager::debugDump()
76 {
77    vjDEBUG(vjDBG_ALL, vjDBG_VERB_LVL)
78       << "------- Thread Manager DUMP -------\n" << vjDEBUG_FLUSH;
79    vjDEBUG_BEGIN(vjDBG_ALL, vjDBG_STATE_LVL) << "--- Thread List ----\n";
80    for (unsigned int i=0;i<mThreads.size();i++)
81    {
82       if (mThreads[i] != NULL)
83          vjDEBUGnl(vjDBG_ALL, vjDBG_STATE_LVL) << i << ": ["
84                                                 << (void*)mThreads[i] << "] "
85                                                 << mThreads[i] << std::endl;
86       else
87          vjDEBUGnl(vjDBG_ALL, vjDBG_STATE_LVL) << i << ": ["
88                                                 << (void*)mThreads[i]
89                                                 << "] No thread\n";
90    }
91
92    vjDEBUG_ENDnl(vjDBG_ALL, vjDBG_STATE_LVL) << "---------------------\n"
93                                               << vjDEBUG_FLUSH;
94 }
95
96
97
98
99
100
Note: See TracBrowser for help on using the browser.