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

  1 karl  1.15 //%2005////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.14 // 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.10 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.14 // 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.15 // 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.11 // Modified By: Steve Hills (steve.hills@ncr.com)
 33            //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 34            //
 35 mike  1.2  //%/////////////////////////////////////////////////////////////////////////////
 36            
 37            
 38            #ifndef ThreadWindows_inline_h
 39            #define ThreadWindows_inline_h
 40            
 41 konrad.r 1.16 inline ThreadStatus Thread::run(void)
 42 mike     1.2  {
 43 kumpf    1.12     // Note: A Win32 thread ID is not the same thing as a pthread ID.
 44                   // Win32 threads have both a thread ID and a handle.  The handle
 45                   // is used in the wait functions, etc.
 46                   // So _handle.thid is actually the thread handle.
 47 s.hills  1.8  
 48 kumpf    1.12     unsigned threadid = 0;
 49                   _handle.thid = (PEGASUS_THREAD_TYPE)
 50                       _beginthreadex(NULL, 0, _start, this, 0, &threadid);
 51                   if (_handle.thid == 0)
 52                   {
 53                       if (errno == EAGAIN)
 54                       {
 55 konrad.r 1.16             return PEGASUS_THREAD_INSUFFICIENT_RESOURCES;
 56 kumpf    1.12         }
 57                       else
 58                       {
 59 konrad.r 1.17             return PEGASUS_THREAD_SETUP_FAILURE;
 60 kumpf    1.12         }
 61                   }
 62 konrad.r 1.16     return PEGASUS_THREAD_OK;
 63 mike     1.2  }
 64               
 65               inline void Thread::cancel(void)
 66               {
 67 s.hills  1.8  	_cancelled = true;
 68 mike     1.2  }
 69               
 70               inline void Thread::test_cancel(void)
 71               {
 72 s.hills  1.8  	if( _cancel_enabled && _cancelled )
 73               	{
 74               		exit_self( 0 );
 75               	}
 76 mike     1.2  }
 77               
 78 mday     1.3  inline Boolean Thread::is_cancelled(void)
 79               {
 80 s.hills  1.8  	return _cancelled;
 81 mday     1.3  }
 82               
 83 mike     1.2  inline void Thread::thread_switch(void)
 84               {
 85 s.hills  1.8  	Sleep( 0 );
 86 mike     1.2  }
 87               
 88 s.hills  1.8  inline void Thread::sleep( Uint32 milliseconds )
 89 mike     1.2  {
 90 s.hills  1.8  	Sleep( milliseconds );
 91 mike     1.2  }
 92               
 93               inline void Thread::join(void)
 94               {
 95 s.hills  1.8  	if( _handle.thid != 0 )
 96               	{
 97               		if( !_is_detached )
 98               		{
 99               			if( !_cancelled )
100               			{
101               				// Emulate the unix join api. Caller sleeps until thread is done.
102               				WaitForSingleObject( _handle.thid, INFINITE );
103               			}
104               			else
105               			{
106               				// Currently this is the only way to ensure this code does not 
107               				// hang forever.
108 s.hills  1.9  				if( WaitForSingleObject( _handle.thid, 10000 ) == WAIT_TIMEOUT )
109               				{
110               					TerminateThread( _handle.thid, 0 );
111               				}
112 s.hills  1.8  			}
113               
114               			DWORD exit_code = 0;
115               			GetExitCodeThread( _handle.thid, &exit_code );
116               			_exit_code = (PEGASUS_THREAD_RETURN)exit_code;
117               		}
118               
119               		CloseHandle( _handle.thid );
120               		_handle.thid = 0;
121               	}
122 mike     1.2  }
123               
124               inline void Thread::thread_init(void)
125               {
126 s.hills  1.8  	_cancel_enabled = true;
127 mike     1.2  }
128               
129               inline void Thread::detach(void)
130               {
131 s.hills  1.8  	_is_detached = true;
132 mike     1.2  }
133               
134               #endif // ThreadWindows_inline_h

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2