ENH: Attempt to remove threading code

This commit is contained in:
Andy Cedilnik 2005-03-01 09:07:38 -05:00
parent 2e00f02112
commit 1191bd7af1
6 changed files with 46 additions and 7 deletions

View File

@ -47,6 +47,10 @@ SET(HAVE_LIBWWW_SSL)
SET(DIRECTORY_SEPARATOR "/") SET(DIRECTORY_SEPARATOR "/")
FIND_PACKAGE(Threads) FIND_PACKAGE(Threads)
SET(HAVE_PTHREADS)
IF(WIN32 OR CMAKE_USE_PTHREADS_INIT)
SET(HAVE_PTHREADS 1)
ENDIF(WIN32 OR CMAKE_USE_PTHREADS_INIT)
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
"${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}"

View File

@ -51,7 +51,7 @@ void xmlrpc_authcookie_set ( xmlrpc_env *env,
sprintf(unencoded, "%s:%s", username, password); sprintf(unencoded, "%s:%s", username, password);
/* Create encoded string. */ /* Create encoded string. */
token = xmlrpc_base64_encode_without_newlines(env, unencoded, token = xmlrpc_base64_encode_without_newlines(env, (unsigned char*)unencoded,
strlen(unencoded)); strlen(unencoded));
XMLRPC_FAIL_IF_FAULT(env); XMLRPC_FAIL_IF_FAULT(env);

View File

@ -30,6 +30,8 @@
#define DIRECTORY_SEPARATOR "@DIRECTORY_SEPARATOR@" #define DIRECTORY_SEPARATOR "@DIRECTORY_SEPARATOR@"
#cmakedefine HAVE_PTHREADS @HAVE_PTHREADS@
/* Xmlrpc-c code uses __inline__ to declare functions that should /* Xmlrpc-c code uses __inline__ to declare functions that should
be compiled as inline code. GNU C recognizes the __inline__ keyword. be compiled as inline code. GNU C recognizes the __inline__ keyword.
Others recognize 'inline' or '__inline' or nothing at all to say Others recognize 'inline' or '__inline' or nothing at all to say

View File

@ -22,7 +22,10 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include "xmlrpc_pthreads.h"
#if defined(HAVE_PTHREADS)
# include "xmlrpc_pthreads.h"
#endif
#include <curl/curl.h> #include <curl/curl.h>
#include <curl/types.h> #include <curl/types.h>
@ -143,7 +146,6 @@ initWindowsStuff(xmlrpc_env * const envP) {
} }
static void static void
create(xmlrpc_env * const envP, create(xmlrpc_env * const envP,
int const flags ATTR_UNUSED, int const flags ATTR_UNUSED,
@ -163,7 +165,9 @@ create(xmlrpc_env * const envP,
envP, XMLRPC_INTERNAL_ERROR, envP, XMLRPC_INTERNAL_ERROR,
"Unable to allocate transport descriptor."); "Unable to allocate transport descriptor.");
else { else {
#ifdef HAVE_PTHREADS
pthread_mutex_init(&transportP->listLock, NULL); pthread_mutex_init(&transportP->listLock, NULL);
#endif
list_make_empty(&transportP->rpcList); list_make_empty(&transportP->rpcList);
@ -183,7 +187,6 @@ create(xmlrpc_env * const envP,
} }
static void static void
termWindowStuff(void) { termWindowStuff(void) {
@ -203,7 +206,9 @@ destroy(struct clientTransport * const clientTransportP) {
XMLRPC_ASSERT(list_is_empty(&clientTransportP->rpcList)); XMLRPC_ASSERT(list_is_empty(&clientTransportP->rpcList));
#if defined(HAVE_PTHREADS)
pthread_mutex_destroy(&clientTransportP->listLock); pthread_mutex_destroy(&clientTransportP->listLock);
#endif
curl_global_cleanup(); curl_global_cleanup();
@ -428,7 +433,7 @@ doAsyncRpc(void * arg) {
#endif #endif
#if defined(HAVE_PTHREADS)
static void static void
createRpcThread(xmlrpc_env * const envP, createRpcThread(xmlrpc_env * const envP,
rpc * const rpcP, rpc * const rpcP,
@ -462,6 +467,7 @@ createRpcThread(xmlrpc_env * const envP,
break; break;
} }
} }
#endif
@ -493,15 +499,23 @@ rpcCreate(xmlrpc_env * const envP,
&rpcP->curlTransactionP); &rpcP->curlTransactionP);
if (!envP->fault_occurred) { if (!envP->fault_occurred) {
if (complete) { if (complete) {
#if defined(HAVE_PTHREADS)
createRpcThread(envP, rpcP, &rpcP->thread); createRpcThread(envP, rpcP, &rpcP->thread);
#else
abort();
#endif
if (!envP->fault_occurred) if (!envP->fault_occurred)
rpcP->threadExists = TRUE; rpcP->threadExists = TRUE;
} }
if (!envP->fault_occurred) { if (!envP->fault_occurred) {
list_init_header(&rpcP->link, rpcP); list_init_header(&rpcP->link, rpcP);
#if defined(HAVE_PTHREADS)
pthread_mutex_lock(&clientTransportP->listLock); pthread_mutex_lock(&clientTransportP->listLock);
#endif
list_add_head(&clientTransportP->rpcList, &rpcP->link); list_add_head(&clientTransportP->rpcList, &rpcP->link);
#if defined(HAVE_PTHREADS)
pthread_mutex_unlock(&clientTransportP->listLock); pthread_mutex_unlock(&clientTransportP->listLock);
#endif
} }
if (envP->fault_occurred) if (envP->fault_occurred)
destroyCurlTransaction(rpcP->curlTransactionP); destroyCurlTransaction(rpcP->curlTransactionP);
@ -513,7 +527,6 @@ rpcCreate(xmlrpc_env * const envP,
} }
static void static void
rpcDestroy(rpc * const rpcP) { rpcDestroy(rpc * const rpcP) {
@ -573,7 +586,11 @@ finishRpc(struct list_head * const headerP,
void *status; void *status;
int result; int result;
#if defined(HAVE_PTHREADS)
result = pthread_join(rpcP->thread, &status); result = pthread_join(rpcP->thread, &status);
#else
abort();
#endif
rpcP->threadExists = FALSE; rpcP->threadExists = FALSE;
} }
@ -601,11 +618,19 @@ finishAsynch(struct clientTransport * const clientTransportP ATTR_UNUSED,
to set an alarm and interrupt running threads. to set an alarm and interrupt running threads.
*/ */
#if defined(HAVE_PTHREADS)
pthread_mutex_lock(&clientTransportP->listLock); pthread_mutex_lock(&clientTransportP->listLock);
#else
abort();
#endif
list_foreach(&clientTransportP->rpcList, finishRpc, NULL); list_foreach(&clientTransportP->rpcList, finishRpc, NULL);
#if defined(HAVE_PTHREADS)
pthread_mutex_unlock(&clientTransportP->listLock); pthread_mutex_unlock(&clientTransportP->listLock);
#else
abort();
#endif
} }

View File

@ -26,6 +26,10 @@
#ifndef xmlrpc_pthreads_h_ #ifndef xmlrpc_pthreads_h_
#define xmlrpc_pthreads_h_ #define xmlrpc_pthreads_h_
#if !defined(HAVE_PTHREADS)
# error This system does not have PThreads
#endif
#ifndef WIN32 #ifndef WIN32
# define _REENTRANT # define _REENTRANT
# include <pthread.h> # include <pthread.h>

View File

@ -6,7 +6,9 @@
extern "C" { extern "C" {
#endif #endif
#include "xmlrpc_pthreads.h" /* For threading helpers. */ #if defined(HAVE_PTHREADS)
# include "xmlrpc_pthreads.h" /* For threading helpers. */
#endif
struct call_info; struct call_info;
@ -67,6 +69,7 @@ struct clientTransportOps {
** Transport Helper Functions and declarations. ** Transport Helper Functions and declarations.
**========================================================================= **=========================================================================
*/ */
#if defined(HAVE_PTHREADS)
typedef struct _running_thread_info typedef struct _running_thread_info
{ {
struct _running_thread_info * Next; struct _running_thread_info * Next;
@ -90,6 +93,7 @@ void register_asynch_thread (running_thread_list *list, pthread_t *thread);
/* MRB-WARNING: Only call when you have successfully /* MRB-WARNING: Only call when you have successfully
** acquired the Lock/Unlock mutex! */ ** acquired the Lock/Unlock mutex! */
void unregister_asynch_thread (running_thread_list *list, pthread_t *thread); void unregister_asynch_thread (running_thread_list *list, pthread_t *thread);
#endif
#ifdef __cplusplus #ifdef __cplusplus