1 kumpf 1.26 //%/////////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 kumpf 1.26 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.2 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 chip 1.21 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
|
12 kumpf 1.26 //
|
13 chip 1.21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
16 chip 1.21 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Day (mdday@us.ibm.com)
25 //
|
26 chip 1.21 // Modified By:
|
27 mike 1.2 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #include <Pegasus/Common/AsyncOpNode.h>
|
31 kumpf 1.22 #include <Pegasus/Common/Exception.h>
|
32 mike 1.2
33 PEGASUS_NAMESPACE_BEGIN
|
34 chip 1.21
|
35 kumpf 1.28 #if defined(PEGASUS_PLATFORM_WIN32_IX86_MSVC)
36 #define snprintf _snprintf
37 #endif
38
|
39 mday 1.19 AsyncOpNode * AsyncOpNode::_headOfFreeList;
|
40 mday 1.20 const int AsyncOpNode::BLOCK_SIZE = 200;
|
41 mday 1.19 Mutex AsyncOpNode::_alloc_mut;
42
43 void * AsyncOpNode::operator new(size_t size)
44 {
45 if(size != sizeof(AsyncOpNode))
46 return :: operator new(size);
|
47 chip 1.21
|
48 mday 1.19 _alloc_mut.lock(pegasus_thread_self());
|
49 chip 1.21
|
50 mday 1.19 AsyncOpNode *node = _headOfFreeList;
51 if(node)
52 _headOfFreeList = node->_parent;
53 else
54 {
|
55 chip 1.21 AsyncOpNode * newBlock =
|
56 mday 1.25 reinterpret_cast<AsyncOpNode *>(::operator new( BLOCK_SIZE * sizeof(AsyncOpNode)));
|
57 mday 1.19 int i;
58 for( i = 1; i < BLOCK_SIZE - 1; ++i)
59 newBlock[i]._parent = &newBlock[i + 1];
60 newBlock[BLOCK_SIZE - 1]._parent = NULL;
61 node = newBlock;
62 _headOfFreeList = &newBlock[1];
63 }
64 _alloc_mut.unlock();
65 return node;
66 }
67
68 void AsyncOpNode::operator delete(void *dead, size_t size)
69 {
70
71 if(dead == 0)
72 return;
73 if(size != sizeof(AsyncOpNode))
74 {
75 ::operator delete(dead);
76 return;
77 }
|
78 mday 1.25 AsyncOpNode *node = reinterpret_cast<AsyncOpNode *>(dead);
|
79 mday 1.19 _alloc_mut.lock(pegasus_thread_self());
80 node->_parent = _headOfFreeList;
81 _headOfFreeList = node;
82 _alloc_mut.unlock();
83 }
84
85
|
86 chip 1.21 AsyncOpNode::AsyncOpNode(void)
87 : _client_sem(0), _request(true), _response(true),
|
88 mday 1.12 _state(0), _flags(0), _offered_count(0), _total_ops(0), _completed_ops(0),
|
89 mday 1.14 _user_data(0), _completion_code(0), _op_dest(0),
|
90 chip 1.21 _parent(0), _children(true), _async_callback(0),__async_callback(0),
91 _callback_node(0), _callback_response_q(0),
92 _callback_ptr(0), _callback_parameter(0),
93 _callback_handle(0), _callback_notify(0), _callback_request_q(0)
|
94 mike 1.2 {
|
95 mday 1.4 gettimeofday(&_start, NULL);
|
96 mike 1.2 memset(&_lifetime, 0x00, sizeof(struct timeval));
97 memset(&_updated, 0x00, sizeof(struct timeval));
|
98 mday 1.10 _timeout_interval.tv_sec = 60;
|
99 mday 1.7 _timeout_interval.tv_usec = 100;
|
100 mike 1.2 }
|
101 chip 1.21
|
102 mike 1.2 AsyncOpNode::~AsyncOpNode(void)
103 {
|
104 mday 1.10 _request.empty_list();
105 _response.empty_list();
|
106 chip 1.21 }
107
|
108 mike 1.2 void AsyncOpNode::_reset(unlocked_dq<AsyncOpNode> *dst_q)
109 {
110 AsyncOpNode *child = _children.remove_first();
111 while( child != 0 )
112 {
113 child->_reset(dst_q);
114 child = _children.remove_first();
115 }
116
117 _parent = 0;
|
118 mday 1.10 _request.empty_list();
119 _response.empty_list();
|
120 chip 1.21
121 //_operation_list.reset();
122 _state = 0;
123 _flags = 0;
|
124 mday 1.12 _offered_count = 0;
|
125 mike 1.2 _total_ops = 0;
126 _completed_ops = 0;
|
127 mday 1.12 _user_data = 0;
128 _completion_code = 0;
|
129 mday 1.14 _op_dest = 0;
|
130 mday 1.13 _async_callback = 0;
|
131 mday 1.19 __async_callback = 0;
|
132 mday 1.14 _callback_node =0;
|
133 chip 1.21 _callback_response_q = 0;
|
134 mday 1.14 _callback_ptr=0;
|
135 mday 1.19 _callback_parameter = 0;
136 _callback_handle = 0;
137 _callback_notify = 0;
|
138 mday 1.17 _callback_request_q = 0;
|
139 mike 1.2 dst_q->insert_first(this);
|
140 mday 1.5 while ( _client_sem.count() )
141 _client_sem.wait();
142 PEGASUS_ASSERT( _client_sem.count() == 0 );
|
143 chip 1.21
|
144 mike 1.2 return;
145 }
146
|
147 mday 1.27 void AsyncOpNode::print_to_buffer(Sint8 **buf)
148 {
149 if(buf == NULL)
150 return;
151
|
152 sage 1.29 #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
153 mday 1.27 static Sint8 work_buf[4096];
154 snprintf(work_buf, 4096, "AsyncOpNode %p\n" \
155 "\trq %d; rp %d; state %d; flags %d; op_dst q %p\n" \
156 "\tcallback node %p; callback rp q %p; callback ptr %p\n" \
157 "\tcallback parm %p; callback handle %p; callback notify %p\n" \
158 "\tcallback rq q %p; service %p; thread %p\n\n",
159 this, _request.count(), _response.count(),
160 _state, _flags, _op_dest, _callback_node, _callback_response_q,
161 _callback_ptr, _callback_parameter, _callback_handle, _callback_notify,
162 _callback_request_q, _service_ptr, _thread_ptr);
163 *buf = strdup(work_buf);
|
164 sage 1.29 #endif
|
165 mday 1.27 return;
166
167 }
168
169 String &AsyncOpNode::print_to_string(void)
170 {
171 static Sint8 work_buf[4096];
|
172 sage 1.29 #if !defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
173 mday 1.27 snprintf(work_buf, 4096, "AsyncOpNode %p\n" \
174 "\trq %d; rp %d; state %d; flags %d; op_dst q %p\n" \
175 "\tcallback node %p; callback rp q %p; callback ptr %p\n" \
176 "\tcallback parm %p; callback handle %p; callback notify %p\n" \
177 "\tcallback rq q %p; service %p; thread %p\n\n",
178 this, _request.count(), _response.count(),
179 _state, _flags, _op_dest, _callback_node, _callback_response_q,
180 _callback_ptr, _callback_parameter, _callback_handle, _callback_notify,
181 _callback_request_q, _service_ptr, _thread_ptr);
|
182 sage 1.29 #else
183 work_buf[0] = (char)0;
184 #endif
|
185 mday 1.27 String *ret = new String(work_buf);
186
187 return *ret;
188 }
189
|
190 mike 1.2 PEGASUS_NAMESPACE_END
|