1 karl 1.8 //%2005////////////////////////////////////////////////////////////////////////
|
2 sage 1.1 //
|
3 karl 1.7 // 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.4 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.7 // 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.8 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 sage 1.1 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.3 // 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 sage 1.1 // 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.3 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 sage 1.1 // 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.3 // 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 sage 1.1 // 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: Markus Mueller (markus_mueller@de.ibm.com)
31 //
|
32 kumpf 1.5 // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
33 sage 1.1 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 // this extra include file is needed, because zOS uses a char[8] for its
37 // thread-id and refuses to accept the long int _handle.thid directly
38
39 #ifndef ThreadzOS_inline_h
40 #define ThreadzOS_inline_h
41
|
42 sage 1.2 typedef struct {
43 void * (PEGASUS_THREAD_CDECL * _start)(void *);
44 void * realParm;
45 } zosParmDef;
46
47 extern "C" { void * _linkage(void * zosParm); };
48
|
49 konrad.r 1.9 inline ThreadStatus Thread::run()
|
50 sage 1.1 {
|
51 sage 1.2 zosParmDef * zosParm = (zosParmDef *)malloc(sizeof(zosParmDef));
52 zosParm->_start = _start;
53 zosParm->realParm = (void *) this;
|
54 sage 1.1 if (_is_detached)
55 {
56 int ds = 1;
57 pthread_attr_setdetachstate(&_handle.thatt, &ds);
58 }
|
59 kumpf 1.5
60 int rc;
61 rc = pthread_create((pthread_t *)&_handle.thid,
62 &_handle.thatt, &_linkage, zosParm);
63 if (rc == EAGAIN)
64 {
65 _handle.thid = 0;
|
66 konrad.r 1.9 return PEGASUS_THREAD_INSUFFICIENT_RESOURCES;
|
67 kumpf 1.5 }
68 else if (rc != 0)
69 {
70 _handle.thid = 0;
|
71 konrad.r 1.9 return PEGASUS_THREAD_SETUP_FAILURE;
|
72 kumpf 1.5 }
|
73 konrad.r 1.9 return PEGASUS_THREAD_OK;
|
74 sage 1.1 }
75
76 inline void Thread::cancel()
77 {
78 _cancelled = true;
79 pthread_cancel(*(pthread_t *)&_handle.thid);
80 }
81
82 inline void Thread::test_cancel()
83 {
84 pthread_testintr();
85 }
86
87 inline Boolean Thread::is_cancelled(void)
88 {
89 return _cancelled;
90 }
91
92 inline void Thread::thread_switch()
93 {
94 pthread_yield(NULL);
95 sage 1.1 }
96
97 inline void Thread::sleep(Uint32 msec)
98 {
99 pegasus_sleep(msec);
100 }
101
102 inline void Thread::join(void)
103 {
104 if((! _is_detached) && (_handle.thid != 0))
105 pthread_join(*(pthread_t *)&_handle.thid, &_exit_code) ;
106 _handle.thid = 0;
107 }
108
109 inline void Thread::thread_init(void)
110 {
111 pthread_setintr(PTHREAD_INTR_ENABLE);
|
112 marek 1.6 pthread_setintrtype(PTHREAD_INTR_ASYNCHRONOUS);
|
113 sage 1.1 _cancel_enabled = true;
114 }
115
116 // *****----- native thread exit routine -----***** //
117
118
119 // *****----- native cleanup routines -----***** //
120
121 inline void Thread::detach(void)
122 {
123 _is_detached = true;
124 pthread_detach((pthread_t *)&_handle.thid);
125 }
126
127 #endif // ThreadzOS_inline_h
|