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

Revision 7539, 4.2 kB (checked in by anonymous, 7 years ago)

This commit was manufactured by cvs2svn to create tag
'RELENG_1_0_5_RELEASE'.

  • 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 <sys/types.h>
36 #include <sys/prctl.h>
37
38 #include <Threads/vjThread.h>
39 #include <Threads/vjThreadSGI.h>
40 #include <Threads/vjThreadManager.h>
41
42 //: Spawning constructor
43 //  This will actually start a new thread
44 //  that will execute the specified function.
45 vjThreadSGI::vjThreadSGI (vj_thread_func_t func, void* arg, long flags,
46              u_int priority, void* stack_addr, size_t stack_size)
47 {
48    mUserThreadFunctor = NULL;
49
50    // Create the thread functor to start
51    mUserThreadFunctor = new vjThreadNonMemberFunctor(func, arg);
52    vjThreadMemberFunctor<vjThreadSGI>* start_functor
53                = new vjThreadMemberFunctor<vjThreadSGI>(this,&vjThreadSGI::startThread,NULL);
54
55    // START THREAD
56    // NOTE: Automagically registers UNLESS failure
57    int ret_val = spawn(start_functor, flags, priority, stack_addr, stack_size);
58
59    if(!ret_val)
60    {
61       vjThreadManager::instance()->lock();
62       {
63          registerThread(false);     // Failed to create
64       }
65       vjThreadManager::instance()->unlock();
66    }
67 }
68
69
70 //: Spawning constructor with arguments (functor version).
71 //   This will start a new
72 //   thread that will execute the specified function.
73 vjThreadSGI::vjThreadSGI ( vjBaseThreadFunctor* functorPtr, long flags,
74               u_int priority, void* stack_addr, size_t stack_size)
75 {
76     mUserThreadFunctor = NULL;
77
78    // Create the thread functor to start
79    mUserThreadFunctor = functorPtr;;
80    vjThreadMemberFunctor<vjThreadSGI>* start_functor
81                = new vjThreadMemberFunctor<vjThreadSGI>(this,&vjThreadSGI::startThread,NULL);
82
83    // START THREAD
84    // NOTE: Automagically registers UNLESS failuer
85    int ret_val = spawn(start_functor, flags, priority, stack_addr, stack_size);
86
87    if(!ret_val)
88    {
89       vjThreadManager::instance()->lock();
90       {
91          registerThread(false);     // Failed to create
92       }
93       vjThreadManager::instance()->unlock();
94    }
95 }
96
97 /**
98  * Called by the spawn routine to start the user thread function
99  * PRE: Called ONLY by a new thread
100  * POST: Do any thread registration necessary
101  *       Call the user thread functor
102  *
103  * @param null_param
104  */
105 void vjThreadSGI::startThread(void* null_param)
106 {
107    // WE are a new thread... yeah!!!!
108    // TELL EVERYONE THAT WE LIVE!!!!
109    vjThreadManager::instance()->lock();      // Lock manager
110    {
111       setLocalThreadPtr(this);               // Store the pointer to me
112       registerThread(true);
113    }
114    vjThreadManager::instance()->unlock();
115
116    // --- CALL USER FUNCTOR --- //
117    (*mUserThreadFunctor)();
118 }
119
120
121 // -----------------------------------------------------------------------
122 //: Make the calling thread wait for the termination of the specified
123 //+ thread.
124 //! NOTE:  Not implemented.
125 //! RETURNS:  0 - Successful completion
126 //! RETURNS: -1 - Error
127 // -----------------------------------------------------------------------
128  int
129 vjThreadSGI::join (void** arg)
130 {
131    std::cerr << "vjThreadSGI::join() not implemented yet!\n";
132    return -1;
133 }
134
Note: See TracBrowser for help on using the browser.