1 karl 1.4 //%2006////////////////////////////////////////////////////////////////////////
|
2 gs.keenan 1.1 //
3 // 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 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 carson.hovey 1.2 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.4 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 gs.keenan 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // 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 // 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 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // 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 // 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 // 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 gs.keenan 1.1 // Modified By: Sean Keenan (sean.keenan@hp.com)
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38
39 #ifndef ThreadVms_inline_h
40 #define ThreadVms_inline_h
41
|
42 konrad.r 1.3 inline ThreadStatus Thread::run()
|
43 gs.keenan 1.1 {
44 if (_is_detached)
45 {
46 pthread_attr_setdetachstate(&_handle.thatt, PTHREAD_CREATE_DETACHED);
47 }
48
49 int rc;
50 rc = pthread_create((pthread_t *)&_handle.thid,
51 &_handle.thatt, _start, this);
|
52 konrad.r 1.3
53 /* On VMS the return code when there is inssuficient resources to create
54 a thread is ENOMEM. The POSIX standard defines that it should be EAGAIN,
55 hence we checking both values.
56
57 For more details:
58 http://aether.lbl.gov/htbin/helpgate/HELP/DECTHREADS/PTHREAD_ROUTINES/PTHREAD_CREATE/RETURN_VALUES
59 */
60 if ((rc == EAGAIN) || (rc==ENOMEM))
|
61 gs.keenan 1.1 {
62 _handle.thid = 0;
|
63 konrad.r 1.3 return PEGASUS_THREAD_INSUFFICIENT_RESOURCES;
|
64 gs.keenan 1.1 }
65 else if (rc != 0)
66 {
67 _handle.thid = 0;
|
68 konrad.r 1.3 return PEGASUS_THREAD_SETUP_FAILURE;
|
69 gs.keenan 1.1 }
|
70 konrad.r 1.3 return PEGASUS_THREAD_OK;
|
71 gs.keenan 1.1 }
72
73
74 inline void Thread::cancel()
75 {
76 _cancelled = true;
77 pthread_cancel(_handle.thid);
78 }
79
80 inline void Thread::test_cancel()
81 {
82 pthread_testcancel();
83 }
84
85 inline Boolean Thread::is_cancelled(void)
86 {
87 return _cancelled;
88 }
89
90 inline void Thread::thread_switch()
91 {
92 gs.keenan 1.1 sched_yield();
93 }
94
95 inline void Thread::sleep(Uint32 msec)
96 {
97 pegasus_sleep(msec);
98 }
99
100 inline void Thread::join(void)
101 {
102 if((! _is_detached) && (_handle.thid != 0))
103 pthread_join(_handle.thid, &_exit_code) ;
104 _handle.thid = 0;
105 }
106
107 inline void Thread::thread_init(void)
108 {
109 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
110 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
111 _cancel_enabled = true;
112 }
113 gs.keenan 1.1
114 inline void Thread::detach(void)
115 {
116 _is_detached = true;
117 pthread_detach(_handle.thid);
118 }
119
120 #endif // ThreadVms_inline_h
|