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

  1 karl  1.10 //%2003////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.10 // 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            // IBM Corp.; EMC Corporation, The Open Group.
  7 mike  1.2  //
  8            // Permission is hereby granted, free of charge, to any person obtaining a copy
  9 kumpf 1.6  // of this software and associated documentation files (the "Software"), to
 10            // deal in the Software without restriction, including without limitation the
 11            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 13            // furnished to do so, subject to the following conditions:
 14            // 
 15 kumpf 1.6  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18 kumpf 1.6  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23            //
 24            //==============================================================================
 25            //
 26            // Author: Mike Day (mdday@us.ibm.com)
 27            //
 28 kumpf 1.11 // Modified By: Steve Hills (steve.hills@ncr.com)
 29            //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 30            //
 31 mike  1.2  //%/////////////////////////////////////////////////////////////////////////////
 32            
 33            
 34            #ifndef ThreadWindows_inline_h
 35            #define ThreadWindows_inline_h
 36            
 37 kumpf 1.11 inline Boolean Thread::run(void)
 38 mike  1.2  {
 39 kumpf 1.12     // Note: A Win32 thread ID is not the same thing as a pthread ID.
 40                // Win32 threads have both a thread ID and a handle.  The handle
 41                // is used in the wait functions, etc.
 42                // So _handle.thid is actually the thread handle.
 43 s.hills 1.8  
 44 kumpf   1.12     unsigned threadid = 0;
 45                  _handle.thid = (PEGASUS_THREAD_TYPE)
 46                      _beginthreadex(NULL, 0, _start, this, 0, &threadid);
 47                  if (_handle.thid == 0)
 48                  {
 49                      if (errno == EAGAIN)
 50                      {
 51                          return false;
 52                      }
 53                      else
 54                      {
 55                          // ATTN: Error behavior has not yet been defined (see Bugzilla 972)
 56                          return true;
 57                      }
 58                  }
 59                  return true;
 60 mike    1.2  }
 61              
 62              inline void Thread::cancel(void)
 63              {
 64 s.hills 1.8  	_cancelled = true;
 65 mike    1.2  }
 66              
 67              inline void Thread::test_cancel(void)
 68              {
 69 s.hills 1.8  	if( _cancel_enabled && _cancelled )
 70              	{
 71              		exit_self( 0 );
 72              	}
 73 mike    1.2  }
 74              
 75 mday    1.3  inline Boolean Thread::is_cancelled(void)
 76              {
 77 s.hills 1.8  	return _cancelled;
 78 mday    1.3  }
 79              
 80 mike    1.2  inline void Thread::thread_switch(void)
 81              {
 82 s.hills 1.8  	Sleep( 0 );
 83 mike    1.2  }
 84              
 85 s.hills 1.8  inline void Thread::sleep( Uint32 milliseconds )
 86 mike    1.2  {
 87 s.hills 1.8  	Sleep( milliseconds );
 88 mike    1.2  }
 89              
 90              inline void Thread::join(void)
 91              {
 92 s.hills 1.8  	if( _handle.thid != 0 )
 93              	{
 94              		if( !_is_detached )
 95              		{
 96              			if( !_cancelled )
 97              			{
 98              				// Emulate the unix join api. Caller sleeps until thread is done.
 99              				WaitForSingleObject( _handle.thid, INFINITE );
100              			}
101              			else
102              			{
103              				// Currently this is the only way to ensure this code does not 
104              				// hang forever.
105 s.hills 1.9  				if( WaitForSingleObject( _handle.thid, 10000 ) == WAIT_TIMEOUT )
106              				{
107              					std::cerr << "Thread::join(): Terminating a thread: handle = " << _handle.thid << std::endl;
108              					TerminateThread( _handle.thid, 0 );
109              				}
110 s.hills 1.8  			}
111              
112              			DWORD exit_code = 0;
113              			GetExitCodeThread( _handle.thid, &exit_code );
114              			_exit_code = (PEGASUS_THREAD_RETURN)exit_code;
115              		}
116              
117              		CloseHandle( _handle.thid );
118              		_handle.thid = 0;
119              	}
120 mike    1.2  }
121              
122              inline void Thread::thread_init(void)
123              {
124 s.hills 1.8  	_cancel_enabled = true;
125 mike    1.2  }
126              
127              inline void Thread::detach(void)
128              {
129 s.hills 1.8  	_is_detached = true;
130 mike    1.2  }
131              
132              #endif // ThreadWindows_inline_h

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2