(file) Return to ThreadUnix_inline.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.16 //%2005////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.15 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.13 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.15 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.16 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 mike  1.2  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.6  // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19 kumpf 1.6  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.6  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Mike Day (mdday@us.ibm.com)
 31            //
 32 kumpf 1.14 // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 33 mike  1.2  //
 34            //%/////////////////////////////////////////////////////////////////////////////
 35            
 36            
 37            #ifndef ThreadUnix_inline_h
 38            #define ThreadUnix_inline_h
 39            
 40 keith.petley 1.12 #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
 41                   // _start wrapper to overcome "C" "C++" binding warnings
 42                   // (code "borrowed" from ThreadzOS_inline.h)
 43                   // Actually the Solaris compiler doesn't need this as "C" "C++"
 44                   // bindings are the same, but it moans like hell about it !!
 45                   // (Its correct to moan, but its a pain all the same).
 46                   
 47                   
 48                   typedef struct {                                   
 49                       void * (PEGASUS_THREAD_CDECL * _start)(void *);
 50                       void * realParm;                               
 51                   } zosParmDef;                                      
 52                   
 53                   extern "C" { void * _linkage(void * zosParm); }
 54                                                                      
 55 konrad.r     1.21 inline ThreadStatus Thread::run()
 56 keith.petley 1.12 {
 57                       zosParmDef * zosParm = (zosParmDef *)malloc(sizeof(zosParmDef));
 58                       zosParm->_start = _start;
 59                       zosParm->realParm = (void *) this;
 60                       if (_is_detached)
 61                       {
 62                           pthread_attr_setdetachstate(&_handle.thatt, PTHREAD_CREATE_DETACHED);
 63                       }
 64                       pthread_attr_setschedpolicy(&_handle.thatt, SCHED_RR);
 65 kumpf        1.14 
 66                       int rc;
 67                       rc = pthread_create((pthread_t *)&_handle.thid,
 68                                           &_handle.thatt, &_linkage, zosParm);
 69 konrad.r     1.21    /* On Sun Solaris, the manpage states that 'ENOMEM' is the error
 70                         code returned when there is no insufficient memory, but the 
 71                         POSIX standard mentions EAGAIN as the proper return code, so
 72                         we checking for both. */ 
 73                       if ((rc == EAGAIN) || (rc==ENOMEM))
 74 kumpf        1.14     {
 75                           _handle.thid = 0;
 76 konrad.r     1.21         return PEGASUS_THREAD_INSUFFICIENT_RESOURCES;
 77 kumpf        1.14     }
 78                       else if (rc != 0)
 79                       {
 80 konrad.r     1.21 	// The error code can be retrieved from  'errno'.
 81 kumpf        1.14         _handle.thid = 0;
 82 konrad.r     1.21 	return PEGASUS_THREAD_SETUP_FAILURE;
 83 kumpf        1.14     }
 84 konrad.r     1.21     return PEGASUS_THREAD_OK;
 85 keith.petley 1.12 }
 86                   #else // PEGASUS_PLATFORM_SOLARIS_SPARC_CC
 87 konrad.r     1.21 inline ThreadStatus Thread::run()
 88 mike         1.2  {
 89                       if (_is_detached)
 90 kumpf        1.14     {
 91 mike         1.2          pthread_attr_setdetachstate(&_handle.thatt, PTHREAD_CREATE_DETACHED);
 92 kumpf        1.14     }
 93                   
 94 chuck        1.10 #ifdef PEGASUS_OS_OS400
 95                       // Initialize the pegasusValue to 1, see IPCOs400.h.
 96                       _handle.thid.pegasusValue = 1;  
 97                   #endif
 98 kumpf        1.14 
 99                       int rc;
100                       rc = pthread_create((pthread_t *)&_handle.thid,
101                                           &_handle.thatt, _start, this);
102 konrad.r     1.21    /* On Linux distributions released prior 2005, the 
103                         implementation of Native POSIX Thread Library 
104                         returns ENOMEM instead of EAGAIN when there are no 
105                         insufficient memory.  Hence we are checking for both. 
106                   
107                         More details can be found : http://sources.redhat.com/bugzilla/show_bug.cgi?id=386
108                       */
109                       if ((rc == EAGAIN) || (rc == ENOMEM))
110 kumpf        1.14     {
111                           _handle.thid = 0;
112 konrad.r     1.21         return PEGASUS_THREAD_INSUFFICIENT_RESOURCES;
113 kumpf        1.14     }
114                       else if (rc != 0)
115                       {
116                           _handle.thid = 0;
117 konrad.r     1.21 	return PEGASUS_THREAD_SETUP_FAILURE;
118 kumpf        1.14     }
119 konrad.r     1.21     return PEGASUS_THREAD_OK;
120 mike         1.2  }
121 keith.petley 1.12 #endif // PEGASUS_PLATFORM_SOLARIS_SPARC_CC
122 mike         1.2  
123                   
124                   inline void Thread::cancel()
125                   {
126 mday         1.3     _cancelled = true;
127                      pthread_cancel(_handle.thid);
128 mike         1.2  }
129                   
130                   inline void Thread::test_cancel()
131                   {
132                     pthread_testcancel();
133 mday         1.3  }
134                   
135                   inline Boolean Thread::is_cancelled(void)
136                   {
137                      return _cancelled;
138 mike         1.2  }
139                   
140                   inline void Thread::thread_switch()
141                   {
142                     sched_yield();
143                   }
144                   
145 david.eger   1.11 #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
146 mike         1.2  inline void Thread::suspend()
147                   {
148                       pthread_kill(_handle.thid,SIGSTOP);
149                   }
150                   
151                   inline void Thread::resume()
152                   {
153                       pthread_kill(_handle.thid,SIGCONT);
154                   }
155                   #endif
156                   
157                   
158                   inline void Thread::sleep(Uint32 msec)
159                   {
160                      pegasus_sleep(msec);
161                   }
162                   
163                   inline void Thread::join(void) 
164                   { 
165                      if((! _is_detached) && (_handle.thid != 0))
166                         pthread_join(_handle.thid, &_exit_code) ; 
167 mday         1.4     _handle.thid = 0;
168 mike         1.2  }
169                   
170                   inline void Thread::thread_init(void)
171                   {
172                     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
173                     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
174                     _cancel_enabled = true;
175                   }
176                   
177                   // *****----- native thread exit routine -----***** //
178                   
179 david.eger   1.11 #if defined(PEGASUS_PLATFORM_HPUX_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
180 mike         1.2  #define PEGASUS_THREAD_EXIT_NATIVE 
181 kumpf        1.20 inline void Thread::exit_self(void *return_code)
182                   {
183                       // NOTE: pthread_exit exhibits unusual behavior on RHEL 3 U2, as
184                       // documented in Bugzilla 3836.  Where feasible, it may be advantageous
185                       // to avoid using this function.
186                       pthread_exit(return_code);
187                   }
188 mike         1.2  #endif
189                   
190                   inline void Thread::detach(void)
191                   {
192                      _is_detached = true;
193                      pthread_detach(_handle.thid);
194                   }
195                   
196                   #endif // ThreadUnix_inline_h

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2