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