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

  1 karl  1.15 //%2004////////////////////////////////////////////////////////////////////////
  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 mike  1.2  //
 10            // Permission is hereby granted, free of charge, to any person obtaining a copy
 11 kumpf 1.6  // of this software and associated documentation files (the "Software"), to
 12            // deal in the Software without restriction, including without limitation the
 13            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 15            // furnished to do so, subject to the following conditions:
 16            // 
 17 kumpf 1.6  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20 kumpf 1.6  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25            //
 26            //==============================================================================
 27            //
 28            // Author: Mike Day (mdday@us.ibm.com)
 29            //
 30 kumpf 1.14 // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 31 mike  1.2  //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            
 35            #ifndef ThreadUnix_inline_h
 36            #define ThreadUnix_inline_h
 37            
 38 keith.petley 1.12 #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
 39                   // _start wrapper to overcome "C" "C++" binding warnings
 40                   // (code "borrowed" from ThreadzOS_inline.h)
 41                   // Actually the Solaris compiler doesn't need this as "C" "C++"
 42                   // bindings are the same, but it moans like hell about it !!
 43                   // (Its correct to moan, but its a pain all the same).
 44                   
 45                   
 46                   typedef struct {                                   
 47                       void * (PEGASUS_THREAD_CDECL * _start)(void *);
 48                       void * realParm;                               
 49                   } zosParmDef;                                      
 50                   
 51                   extern "C" { void * _linkage(void * zosParm); }
 52                                                                      
 53 kumpf        1.14 inline Boolean Thread::run()
 54 keith.petley 1.12 {
 55                       zosParmDef * zosParm = (zosParmDef *)malloc(sizeof(zosParmDef));
 56                       zosParm->_start = _start;
 57                       zosParm->realParm = (void *) this;
 58                       if (_is_detached)
 59                       {
 60                           pthread_attr_setdetachstate(&_handle.thatt, PTHREAD_CREATE_DETACHED);
 61                       }
 62                       pthread_attr_setschedpolicy(&_handle.thatt, SCHED_RR);
 63 kumpf        1.14 
 64                       int rc;
 65                       rc = pthread_create((pthread_t *)&_handle.thid,
 66                                           &_handle.thatt, &_linkage, zosParm);
 67                       if (rc == EAGAIN)
 68                       {
 69                           _handle.thid = 0;
 70                           return false;
 71                       }
 72                       else if (rc != 0)
 73                       {
 74                           // ATTN: Error behavior has not yet been defined (see Bugzilla 972)
 75                           _handle.thid = 0;
 76                           return true;
 77                       }
 78                       return true;
 79 keith.petley 1.12 }
 80                   #else // PEGASUS_PLATFORM_SOLARIS_SPARC_CC
 81 kumpf        1.14 inline Boolean Thread::run()
 82 mike         1.2  {
 83                       if (_is_detached)
 84 kumpf        1.14     {
 85 mike         1.2          pthread_attr_setdetachstate(&_handle.thatt, PTHREAD_CREATE_DETACHED);
 86 kumpf        1.14     }
 87                   
 88 chuck        1.10 #ifdef PEGASUS_OS_OS400
 89                       // Initialize the pegasusValue to 1, see IPCOs400.h.
 90                       _handle.thid.pegasusValue = 1;  
 91                   #endif
 92 kumpf        1.14 
 93                       int rc;
 94                       rc = pthread_create((pthread_t *)&_handle.thid,
 95                                           &_handle.thatt, _start, this);
 96                       if (rc == EAGAIN)
 97                       {
 98                           _handle.thid = 0;
 99                           return false;
100                       }
101                       else if (rc != 0)
102                       {
103                           // ATTN: Error behavior has not yet been defined (see Bugzilla 972)
104                           _handle.thid = 0;
105                           return true;
106                       }
107                       return true;
108 mike         1.2  }
109 keith.petley 1.12 #endif // PEGASUS_PLATFORM_SOLARIS_SPARC_CC
110 mike         1.2  
111                   
112                   inline void Thread::cancel()
113                   {
114 mday         1.3     _cancelled = true;
115                      pthread_cancel(_handle.thid);
116 mike         1.2  }
117                   
118                   inline void Thread::test_cancel()
119                   {
120                     pthread_testcancel();
121 mday         1.3  }
122                   
123                   inline Boolean Thread::is_cancelled(void)
124                   {
125                      return _cancelled;
126 mike         1.2  }
127                   
128                   inline void Thread::thread_switch()
129                   {
130                     sched_yield();
131                   }
132                   
133 david.eger   1.11 #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
134 mike         1.2  inline void Thread::suspend()
135                   {
136                       pthread_kill(_handle.thid,SIGSTOP);
137                   }
138                   
139                   inline void Thread::resume()
140                   {
141                       pthread_kill(_handle.thid,SIGCONT);
142                   }
143                   #endif
144                   
145                   
146                   inline void Thread::sleep(Uint32 msec)
147                   {
148                      pegasus_sleep(msec);
149                   }
150                   
151                   inline void Thread::join(void) 
152                   { 
153                      if((! _is_detached) && (_handle.thid != 0))
154                         pthread_join(_handle.thid, &_exit_code) ; 
155 mday         1.4     _handle.thid = 0;
156 mike         1.2  }
157                   
158                   inline void Thread::thread_init(void)
159                   {
160                     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
161                     pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
162                     _cancel_enabled = true;
163                   }
164                   
165                   // *****----- native thread exit routine -----***** //
166                   
167 david.eger   1.11 #if defined(PEGASUS_PLATFORM_HPUX_ACC) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
168 mike         1.2  #define PEGASUS_THREAD_EXIT_NATIVE 
169                   inline void Thread::exit_self(void *return_code) { pthread_exit(return_code) ; }
170                   #endif
171                   
172                   // *****----- native cleanup routines -----***** //
173 david.eger   1.11 #if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
174 mike         1.2  #define PEGASUS_THREAD_CLEANUP_NATIVE 
175                   inline void Thread::cleanup_push( void (*routine)(void *), void *parm) throw(IPCException)
176                   {
177                      cleanup_handler *cu = new cleanup_handler(routine, parm);
178                      try { _cleanup.insert_first(cu); } 
179                      catch(IPCException& e) { delete cu; throw; }
180                      _pthread_cleanup_push(&(cu->_cleanup_buffer), routine, parm);
181                      return;
182                   }
183                   
184                   
185 kumpf        1.9  inline void Thread::cleanup_pop(Boolean execute) throw(IPCException)
186 mike         1.2  {
187 w.otsuka     1.15.2.1    cleanup_handler *cu = 0;
188 mike         1.2         try { cu = static_cast<cleanup_handler *>(_cleanup.remove_first()) ;}
189                          catch(IPCException& e) { PEGASUS_ASSERT(0); }
190                          _pthread_cleanup_pop(&(cu->_cleanup_buffer), execute);
191                          delete cu;
192                       }
193                       
194                       #endif 
195                       
196                       inline void Thread::detach(void)
197                       {
198                          _is_detached = true;
199                          pthread_detach(_handle.thid);
200                       }
201                       
202                       #endif // ThreadUnix_inline_h

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2