You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2006/02/13 11:43:48 UTC
svn commit: r377336 - in /webservices/axis2/trunk/c: include/
modules/core/transport/http/receiver/ modules/core/transport/http/server/
modules/platforms/unix/ modules/util/ test/util/
Author: sahan
Date: Mon Feb 13 02:43:46 2006
New Revision: 377336
URL: http://svn.apache.org/viewcvs?rev=377336&view=rev
Log:
Threading support. Mutex lock implementation. Server is still single threaded
Modified:
webservices/axis2/trunk/c/include/axis2_env.h
webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c
webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c
webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am
webservices/axis2/trunk/c/modules/platforms/unix/axis2_thread_unix.h
webservices/axis2/trunk/c/modules/platforms/unix/thread_unix.c
webservices/axis2/trunk/c/modules/util/Makefile.am
webservices/axis2/trunk/c/modules/util/env.c
webservices/axis2/trunk/c/test/util/Makefile.am
webservices/axis2/trunk/c/test/util/test_thread.c
Modified: webservices/axis2/trunk/c/include/axis2_env.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_env.h?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_env.h (original)
+++ webservices/axis2/trunk/c/include/axis2_env.h Mon Feb 13 02:43:46 2006
@@ -26,6 +26,7 @@
#include <axis2_allocator.h>
#include <axis2_error.h>
#include <axis2_log.h>
+#include <axis2_thread_pool.h>
#ifdef __cplusplus
extern "C"
@@ -64,7 +65,8 @@
axis2_log_t *log;
/** This flag indicate whether logging is enabled or not */
axis2_bool_t log_enabled;
-
+ /** Thread pooling routines */
+ axis2_thread_pool_t *thread_pool;
} axis2_env_t;
/**
@@ -80,7 +82,6 @@
* Creates an environment struct
* @param allocator pointer to an instance of allocator struct. Must be non-NULL
* @param error pointer to an instance of error struct. Must be non-NULL.
- * @param stream pointer to an instance of stream struct. Must be non-NULL.
* it would be taken as a flag for no logging.
* @return pointer to the newly created environment struct
*/
@@ -92,7 +93,6 @@
* Creates an environment struct
* @param allocator pointer to an instance of allocator struct. Must be non-NULL
* @param error pointer to an instance of error struct. Must be non-NULL.
- * @param stream pointer to an instance of stream struct. Must be non-NULL.
* @param log pointer to an instance of log struct. May be NULL. If NULL
* it would be taken as a flag for no logging.
* @return pointer to the newly created environment struct
@@ -101,12 +101,26 @@
(axis2_allocator_t *allocator
, axis2_error_t *error
, axis2_log_t *log);
+
+ /**
+ * Creates an environment struct
+ * @param allocator pointer to an instance of allocator struct. Must be non-NULL
+ * @param error pointer to an instance of error struct. Must be non-NULL.
+ * @param log pointer to an instance of log struct. May be NULL. If NULL
+ * it would be taken as a flag for no logging.
+ * @param pool pointer to an instance of thread_pool. May be NULL. If NULL
+ * @return pointer to the newly created environment struct
+ */
+ AXIS2_DECLARE(axis2_env_t *) axis2_env_create_with_error_log_thread_pool
+ (axis2_allocator_t *allocator
+ , axis2_error_t *error
+ , axis2_log_t *log
+ , axis2_thread_pool_t *pool);
/**
* Creates an environment struct
* @param allocator pointer to an instance of allocator struct. Mandatory, cannot be NULL
* @param error pointer to an instance of error struct. Optional, can be NULL. If NULL default error handler would be used.
- * @param stream pointer to an instance of stream struct. Optional, can be NULL. If NULL default stream handler would be used.
* @param log pointer to an instance of log struct. Optional, can be NULL. If NULL default log handler would be used.
* @param string pointer to an instance of string struct. Optional, can be NULL. If NULL default string handler would be used.
* @return pointer to the newly created environment struct
Modified: webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c Mon Feb 13 02:43:46 2006
@@ -22,6 +22,7 @@
#include <axis2_http_simple_request.h>
#include <axis2_simple_http_svr_conn.h>
#include <axis2_url.h>
+#include <axis2_error_default.h>
@@ -30,7 +31,7 @@
* Axis2 HTTP Server Thread impl
*/
typedef struct axis2_http_svr_thread_impl axis2_http_svr_thread_impl_t;
-
+typedef struct axis2_http_svr_thd_args axis2_http_svr_thd_args_t;
struct axis2_http_svr_thread_impl
{
axis2_http_svr_thread_t svr_thread;
@@ -40,6 +41,14 @@
int port;
};
+struct axis2_http_svr_thd_args
+{
+ axis2_env_t **env;
+ axis2_socket_t socket;
+ axis2_http_worker_t *worker;
+};
+
+
#define AXIS2_INTF_TO_IMPL(http_svr_thread) \
((axis2_http_svr_thread_impl_t *)(http_svr_thread))
@@ -62,8 +71,12 @@
axis2_env_t **env, axis2_http_worker_t *worker);
axis2_status_t AXIS2_CALL
axis2_http_svr_thread_free (axis2_http_svr_thread_t *svr_thread,
- axis2_env_t **env);
+ axis2_env_t **env);
+AXIS2_DECLARE (axis2_env_t*)
+init_thread_env(axis2_env_t **system_env);
+void * AXIS2_THREAD_FUNC
+worker_func(axis2_thread_t *thd, void *data);
/***************************** End of function headers ************************/
axis2_http_svr_thread_t* AXIS2_CALL
@@ -158,13 +171,7 @@
while(AXIS2_FALSE == svr_thread_impl->stopped)
{
int socket = -1;
- struct AXIS2_PLATFORM_TIMEB t1, t2;
- axis2_simple_http_svr_conn_t *svr_conn = NULL;
- axis2_http_simple_request_t *request = NULL;
- int millisecs = 0;
- double secs = 0;
- axis2_http_worker_t *tmp = NULL;
- axis2_status_t status = AXIS2_FAILURE;
+ axis2_http_svr_thd_args_t *arg_list = NULL;
socket = axis2_network_handler_svr_socket_accept(env,
svr_thread_impl->listen_socket);
@@ -172,35 +179,18 @@
{
continue;
}
- /* This block goes inside thread execution */
+ arg_list = AXIS2_MALLOC((*env)->allocator,
+ sizeof(axis2_http_svr_thd_args_t));
+ if(NULL == arg_list)
{
- AXIS2_PLATFORM_GET_TIME_IN_MILLIS(&t1);
- svr_conn = axis2_simple_http_svr_conn_create(env, socket);
- AXIS2_SIMPLE_HTTP_SVR_CONN_SET_RCV_TIMEOUT(svr_conn, env,
- axis2_http_socket_read_timeout);
- request = AXIS2_SIMPLE_HTTP_SVR_CONN_READ_REQUEST(svr_conn, env);
- tmp = svr_thread_impl->worker;
- status = AXIS2_HTTP_WORKER_PROCESS_REQUEST(tmp, env, svr_conn, request);
- AXIS2_SIMPLE_HTTP_SVR_CONN_FREE(svr_conn, env);
- AXIS2_PLATFORM_GET_TIME_IN_MILLIS(&t2);
- millisecs = t2.millitm - t1.millitm;
- secs = difftime(t2.time, t1.time);
- if(millisecs < 0)
- {
- millisecs += 1000;
- secs--;
- }
- secs += millisecs/1000.0;
- if(status == AXIS2_SUCCESS)
- {
- AXIS2_LOG_INFO((*env)->log, "Request served in %.3f seconds", secs);
- }
- else
- {
- AXIS2_LOG_INFO((*env)->log, "Error occured in processing request."
- "(%.3f seconds)", secs);
- }
+ AXIS2_LOG_ERROR((*env)->log, AXIS2_LOG_SI,
+ "Memory allocation error in the svr thread loop");
+ continue;
}
+ arg_list->env = env;
+ arg_list->socket = socket;
+ arg_list->worker = svr_thread_impl->worker;
+ worker_func(NULL, (void*)arg_list);
}
return AXIS2_SUCCESS;
}
@@ -256,4 +246,72 @@
AXIS2_PARAM_CHECK((*env)->error, worker, AXIS2_FAILURE);
AXIS2_INTF_TO_IMPL(svr_thread)->worker = worker;
return AXIS2_SUCCESS;
+}
+
+
+AXIS2_DECLARE (axis2_env_t*)
+axis2_init_thread_env(axis2_env_t **system_env)
+{
+ axis2_error_t *error = axis2_error_create((*system_env)->allocator);
+ return axis2_env_create_with_error_log((*system_env)->allocator, error,
+ (*system_env)->log);
+}
+
+/**
+ * Thread worker function.
+ */
+void * AXIS2_THREAD_FUNC
+worker_func(axis2_thread_t *thd, void *data)
+{
+ struct AXIS2_PLATFORM_TIMEB t1, t2;
+ axis2_simple_http_svr_conn_t *svr_conn = NULL;
+ axis2_http_simple_request_t *request = NULL;
+ int millisecs = 0;
+ double secs = 0;
+ axis2_http_worker_t *tmp = NULL;
+ axis2_status_t status = AXIS2_FAILURE;
+ axis2_env_t **env = NULL;
+ axis2_socket_t socket;
+ axis2_env_t *thread_env = NULL;
+ axis2_http_svr_thd_args_t *arg_list = NULL;
+
+
+ arg_list = (axis2_http_svr_thd_args_t*)data;
+ if(NULL == arg_list)
+ {
+ return NULL;
+ }
+ AXIS2_PLATFORM_GET_TIME_IN_MILLIS(&t1);
+ env = arg_list->env;
+ thread_env = axis2_init_thread_env(env);
+ socket = arg_list->socket;
+ svr_conn = axis2_simple_http_svr_conn_create(&thread_env, socket);
+ AXIS2_SIMPLE_HTTP_SVR_CONN_SET_RCV_TIMEOUT(svr_conn, &thread_env,
+ axis2_http_socket_read_timeout);
+ request = AXIS2_SIMPLE_HTTP_SVR_CONN_READ_REQUEST(svr_conn, &thread_env);
+ tmp = arg_list->worker;
+ status = AXIS2_HTTP_WORKER_PROCESS_REQUEST(tmp, &thread_env, svr_conn,
+ request);
+ AXIS2_SIMPLE_HTTP_SVR_CONN_FREE(svr_conn, &thread_env);
+ AXIS2_FREE((*env)->allocator, arg_list);
+ AXIS2_PLATFORM_GET_TIME_IN_MILLIS(&t2);
+ millisecs = t2.millitm - t1.millitm;
+ secs = difftime(t2.time, t1.time);
+ if(millisecs < 0)
+ {
+ millisecs += 1000;
+ secs--;
+ }
+ secs += millisecs/1000.0;
+ if(status == AXIS2_SUCCESS)
+ {
+ AXIS2_LOG_INFO(thread_env->log, "Request served in %.3f seconds", secs);
+ }
+ else
+ {
+ AXIS2_LOG_WARNING(thread_env->log, AXIS2_LOG_SI,
+ "Error occured in processing request (%.3f seconds)",
+ secs);
+ }
+ return NULL;
}
Modified: webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c Mon Feb 13 02:43:46 2006
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <axis2_error_default.h>
#include <axis2_log_default.h>
+#include <axis2_thread_pool.h>
/***************************** Function headers *******************************/
@@ -32,7 +33,9 @@
{
axis2_error_t *error = axis2_error_create(allocator);
axis2_log_t *log = axis2_log_create(allocator, NULL, log_file);
- return axis2_env_create_with_error_log(allocator, error, log);
+ axis2_thread_pool_t *thread_pool = axis2_thread_pool_init(allocator);
+ return axis2_env_create_with_error_log_thread_pool(allocator, error, log,
+ thread_pool);
}
void system_exit(axis2_allocator_t *allocator, axis2_env_t *env, int status)
Modified: webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am (original)
+++ webservices/axis2/trunk/c/modules/platforms/unix/Makefile.am Mon Feb 13 02:43:46 2006
@@ -6,7 +6,8 @@
axis2_uuid_gen_unix.h
AM_CPPFLAGS = $(CPPFLAGS)
-libaxis2_unix_la_SOURCES = uuid_gen_unix.c
+libaxis2_unix_la_SOURCES = uuid_gen_unix.c\
+ thread_unix.c
INCLUDES = -I$(top_builddir)/include \
-I$(top_builddir)/modules/platforms \
Modified: webservices/axis2/trunk/c/modules/platforms/unix/axis2_thread_unix.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/platforms/unix/axis2_thread_unix.h?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/platforms/unix/axis2_thread_unix.h (original)
+++ webservices/axis2/trunk/c/modules/platforms/unix/axis2_thread_unix.h Mon Feb 13 02:43:46 2006
@@ -42,4 +42,10 @@
pthread_once_t once;
};
+/*************************Thread locking functions*****************************/
+struct axis2_thread_mutex_t {
+ axis2_allocator_t *allocator;
+ pthread_mutex_t mutex;
+};
+
#endif /* AXIS2_THREAD_UNIX_H */
Modified: webservices/axis2/trunk/c/modules/platforms/unix/thread_unix.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/platforms/unix/thread_unix.c?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/platforms/unix/thread_unix.c (original)
+++ webservices/axis2/trunk/c/modules/platforms/unix/thread_unix.c Mon Feb 13 02:43:46 2006
@@ -56,8 +56,8 @@
#define DETACH_ARG(v) ((v) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE)
-AXIS2_DECLARE(axis2_status_t) axis2_threadattr_detach_set(
- axis2_threadattr_t *attr, axis2_bool_t detached)
+AXIS2_DECLARE(axis2_status_t)
+axis2_threadattr_detach_set(axis2_threadattr_t *attr, axis2_bool_t detached)
{
if (0 == pthread_attr_setdetachstate(&attr->attr, DETACH_ARG(detached)))
{
@@ -196,4 +196,48 @@
axis2_thread_once(axis2_thread_once_t *control, void (*func)(void))
{
return pthread_once(&control->once, func);
+}
+
+/*************************Thread locking functions*****************************/
+AXIS2_DECLARE(axis2_thread_mutex_t *)
+axis2_thread_mutex_create(axis2_allocator_t *allocator, unsigned int flags)
+{
+ axis2_thread_mutex_t *new_mutex = NULL;
+
+ new_mutex = AXIS2_MALLOC(allocator, sizeof(axis2_thread_mutex_t));
+ new_mutex->allocator = allocator;
+
+ if (pthread_mutex_init(&new_mutex->mutex, NULL) != 0)
+ {
+ AXIS2_FREE(allocator, new_mutex);
+ return NULL;
+ }
+ return new_mutex;
+}
+
+AXIS2_DECLARE(axis2_status_t)
+axis2_thread_mutex_lock(axis2_thread_mutex_t *mutex)
+{
+ return pthread_mutex_lock(&mutex->mutex);
+}
+
+AXIS2_DECLARE(axis2_status_t)
+axis2_thread_mutex_unlock(axis2_thread_mutex_t *mutex)
+{
+ if(pthread_mutex_unlock(&mutex->mutex) != 0)
+ {
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_DECLARE(axis2_status_t)
+axis2_thread_mutex_destroy(axis2_thread_mutex_t *mutex)
+{
+ if(0 != pthread_mutex_destroy(&mutex->mutex))
+ {
+ return AXIS2_FAILURE;
+ }
+ AXIS2_FREE(mutex->allocator, mutex);
+ return AXIS2_SUCCESS;
}
Modified: webservices/axis2/trunk/c/modules/util/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/Makefile.am?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/Makefile.am (original)
+++ webservices/axis2/trunk/c/modules/util/Makefile.am Mon Feb 13 02:43:46 2006
@@ -27,7 +27,8 @@
class_loader.c\
network_handler.c \
file.c\
- uuid_gen.c
+ uuid_gen.c\
+ thread_pool.c
INCLUDES = -I$(top_builddir)/include \
-I$(top_builddir)/modules/util \
Modified: webservices/axis2/trunk/c/modules/util/env.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/env.c?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/env.c (original)
+++ webservices/axis2/trunk/c/modules/util/env.c Mon Feb 13 02:43:46 2006
@@ -53,7 +53,7 @@
environment->error = axis2_error_create (allocator);
if(NULL == environment->error)
return NULL;
-
+ environment->thread_pool = NULL;
return environment;
}
@@ -74,6 +74,8 @@
axis2_env_t *environment;
if (NULL == allocator)
return NULL;
+ if (NULL == error)
+ return NULL;
environment =
(axis2_env_t *) AXIS2_MALLOC (allocator,
@@ -83,11 +85,40 @@
return NULL;
environment->allocator = allocator;
+ environment->error = error;
+
+
+ if (NULL == log)
+ environment->log_enabled = AXIS2_FALSE;
+ environment->log_enabled = AXIS2_TRUE;
+ environment->log = log;
+ environment->thread_pool = NULL;
+ return environment;
+}
+
+AXIS2_DECLARE(axis2_env_t *)
+axis2_env_create_with_error_log_thread_pool (axis2_allocator_t *allocator
+ , axis2_error_t *error
+ , axis2_log_t *log
+ , axis2_thread_pool_t *pool)
+{
+ axis2_env_t *environment;
+ if (NULL == allocator)
+ return NULL;
+ if (NULL == error)
+ return NULL;
+ if(NULL == pool)
+ return NULL;
+
+ environment =
+ (axis2_env_t *) AXIS2_MALLOC (allocator, sizeof (axis2_env_t));
- if (NULL == error)
+ if (NULL == environment)
return NULL;
- environment->error = error;
+ environment->allocator = allocator;
+ environment->error = error;
+ environment->thread_pool = pool;
if (NULL == log)
environment->log_enabled = AXIS2_FALSE;
@@ -96,7 +127,6 @@
return environment;
}
-
AXIS2_DECLARE( axis2_status_t )
axis2_env_check_status (axis2_env_t **env)
Modified: webservices/axis2/trunk/c/test/util/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/test/util/Makefile.am?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/test/util/Makefile.am (original)
+++ webservices/axis2/trunk/c/test/util/Makefile.am Mon Feb 13 02:43:46 2006
@@ -5,10 +5,11 @@
check_PROGRAMS = test_util
SUBDIRS =
AM_CPPFLAGS = $(CPPFLAGS)
-test_util_SOURCES = test_util.c test_log.c
+test_util_SOURCES = test_util.c test_log.c test_thread.c
test_util_LDADD = -L$(AXIS2C_HOME)/lib -laxis2_util \
- -laxis2_unix
+ -laxis2_unix\
+ -lpthread
INCLUDES = -I$(top_builddir)/include \
-I$(top_builddir)/modules/util \
Modified: webservices/axis2/trunk/c/test/util/test_thread.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/test/util/test_thread.c?rev=377336&r1=377335&r2=377336&view=diff
==============================================================================
--- webservices/axis2/trunk/c/test/util/test_thread.c (original)
+++ webservices/axis2/trunk/c/test/util/test_thread.c Mon Feb 13 02:43:46 2006
@@ -21,7 +21,6 @@
#include <axis2_log_default.h>
#include <axis2_allocator.h>
#include <axis2.h>
-#include <axis2_thread_mutex.h>
#include "test_thread.h"
@@ -55,7 +54,7 @@
if (AXIS2_SUCCESS == rv) printf("success - thread_init - axis2_thread_once_init \n");
else printf("failure - thread_init - axis2_thread_once_init \n");
- thread_lock = axis2_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_UNNESTED);
+ thread_lock = axis2_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_DEFAULT);
if (NULL != thread_lock) printf("success - thread_init - axis2_thread_mutex_create \n");
else printf("failure - thread_init - axis2_thread_mutex_create \n");