1 /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
6 ** 1. Redistributions of source code must retain the above copyright
7 ** notice, this list of conditions and the following disclaimer.
8 ** 2. Redistributions in binary form must reproduce the above copyright
9 ** notice, this list of conditions and the following disclaimer in the
10 ** documentation and/or other materials provided with the distribution.
11 ** 3. The name of the author may not be used to endorse or promote products
12 ** derived from this software without specific prior written permission.
14 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include "xmlrpc_config.h"
38 # define new DEBUG_NEW
39 # define malloc(size) _malloc_dbg( size, _NORMAL_BLOCK, __FILE__, __LINE__)
41 static char THIS_FILE
[] = __FILE__
;
46 #include "xmlrpc_client.h"
52 /* For debugging the xmlrpc_transport threading. */
53 /* #define tdbg_printf printf */
54 #define tdbg_printf (void *)
56 /* Lacking from the abyss/thread.c implimentaion. */
57 void wait_for_asynch_thread(pthread_t
*thread
)
60 unsigned long milliseconds
= INFINITE
;
61 switch (WaitForSingleObject (
62 *thread
/* handle to object to wait for */,
63 milliseconds
/* time-out interval in milliseconds*/) )
65 /* One may want to handle these cases */
73 success
= pthread_join (*thread
, &result
);
77 /* MRB-WARNING: Only call when you have successfully
78 ** acquired the Lock/Unlock mutex! */
79 void unregister_asynch_thread (running_thread_list
*list
, pthread_t
*thread
)
81 running_thread_info
* pCur
= NULL
;
82 XMLRPC_ASSERT_PTR_OK(thread
);
83 XMLRPC_ASSERT_PTR_OK(list
);
85 tdbg_printf("unregister_asynch_thread: &pthread_id = %08X *(%08X)\n", thread
, *thread
);
88 for (pCur
= list
->AsyncThreadHead
; pCur
!= NULL
; pCur
= (running_thread_info
*)pCur
->Next
)
90 if (pCur
->_thread
== *thread
)
92 if (pCur
== list
->AsyncThreadHead
)
93 list
->AsyncThreadHead
= pCur
->Next
;
94 if (pCur
== list
->AsyncThreadTail
)
95 list
->AsyncThreadTail
= pCur
->Last
;
97 ((running_thread_info
*)(pCur
->Last
))->Next
= pCur
->Next
;
99 ((running_thread_info
*)(pCur
->Next
))->Last
= pCur
->Last
;
100 /* Free malloc'd running_thread_info */
106 /* This is a serious progmatic error, since the thread
107 ** should be in that list! */
108 XMLRPC_ASSERT_PTR_OK(0x0000);
113 /* MRB-WARNING: Only call when you have successfully
114 ** acquired the Lock/Unlock mutex! */
115 void register_asynch_thread (running_thread_list
*list
, pthread_t
*thread
)
117 running_thread_info
* info
= (running_thread_info
*) malloc(sizeof(running_thread_info
));
119 XMLRPC_ASSERT_PTR_OK(thread
);
120 XMLRPC_ASSERT_PTR_OK(list
);
122 tdbg_printf("register_asynch_thread: &pthread_id = %08X *(%08X)\n", thread
, *thread
);
124 info
->_thread
= *thread
;
128 if (list
->AsyncThreadHead
== NULL
)
130 list
->AsyncThreadHead
= list
->AsyncThreadTail
= info
;
131 list
->AsyncThreadTail
->Next
= list
->AsyncThreadHead
->Next
= NULL
;
132 list
->AsyncThreadTail
->Last
= list
->AsyncThreadHead
->Last
= NULL
;
136 info
->Last
= list
->AsyncThreadTail
;
137 list
->AsyncThreadTail
->Next
= info
;
138 list
->AsyncThreadTail
= list
->AsyncThreadTail
->Next
;
139 list
->AsyncThreadTail
->Next
= NULL
;