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/10 15:06:38 UTC
svn commit: r376693 - in /webservices/axis2/trunk/c: include/axis2_thread.h
include/axis2_thread_pool.h modules/util/network_handler.c
modules/util/stream.c modules/util/thread_pool.c modules/util/uuid_gen.c
Author: sahan
Date: Fri Feb 10 06:06:36 2006
New Revision: 376693
URL: http://svn.apache.org/viewcvs?rev=376693&view=rev
Log:
Added thread pool and removed some warnings
Added:
webservices/axis2/trunk/c/include/axis2_thread_pool.h
webservices/axis2/trunk/c/modules/util/thread_pool.c
Modified:
webservices/axis2/trunk/c/include/axis2_thread.h
webservices/axis2/trunk/c/modules/util/network_handler.c
webservices/axis2/trunk/c/modules/util/stream.c
webservices/axis2/trunk/c/modules/util/uuid_gen.c
Modified: webservices/axis2/trunk/c/include/axis2_thread.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_thread.h?rev=376693&r1=376692&r2=376693&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_thread.h (original)
+++ webservices/axis2/trunk/c/include/axis2_thread.h Fri Feb 10 06:06:36 2006
@@ -23,9 +23,8 @@
* @brief axis2 thread api
*/
-#include <axis2.h>
-#include <axis2_defines.h>
#include <axis2_allocator.h>
+#include <axis2.h>
@@ -69,7 +68,8 @@
* @param cont The pool to use
* @return Newly created thread attribute
*/
-AXIS2_DECLARE(axis2_threadattr_t*) axis2_threadattr_create(axis2_env_t **env);
+AXIS2_DECLARE(axis2_threadattr_t*) axis2_threadattr_create(
+ axis2_allocator_t *allocator);
/**
* Set if newly created threads should be created in detached state.
@@ -78,8 +78,7 @@
* @return The status of the operation
*/
AXIS2_DECLARE(axis2_status_t) axis2_threadattr_detach_set(
- axis2_threadattr_t *attr, axis2_env_t **env,
- axis2_bool_t detached);
+ axis2_threadattr_t *attr, axis2_bool_t detached);
/**
* Get the detach state for this threadattr.
@@ -99,32 +98,29 @@
* @param cont The pool to use
* @return The newly created thread handle.
*/
-AXIS2_DECLARE(axis2_thread_t*) axis2_thread_create(axis2_env_t **env,
+AXIS2_DECLARE(axis2_thread_t*) axis2_thread_create(axis2_allocator_t *allocator,
axis2_threadattr_t *attr,
axis2_thread_start_t func,
void *data);
/**
- * stop the current thread
+ * Stop the current thread
* @param thd The thread to stop
* @return The status of the operation
*/
-AXIS2_DECLARE(axis2_status_t) axis2_thread_exit(axis2_thread_t *thd,
- axis2_env_t **env);
+AXIS2_DECLARE(axis2_status_t) axis2_thread_exit(axis2_thread_t *thd);
/**
- * block until the desired thread stops executing.
- * @param retval The return value from the dead thread.
+ * Block until the desired thread stops executing.
* @param thd The thread to join
* @return The status of the operation
*/
-AXIS2_DECLARE(axis2_status_t) axis2_thread_join(axis2_thread_t *thd,
- axis2_env_t **env);
+AXIS2_DECLARE(axis2_status_t) axis2_thread_join(axis2_thread_t *thd);
/**
* force the current thread to yield the processor
*/
-AXIS2_DECLARE(void) axis2_thread_yield(axis2_env_t **env);
+AXIS2_DECLARE(void) axis2_thread_yield();
/**
* Initialize the control variable for axis2_thread_once.
@@ -132,7 +128,8 @@
* @return The status of the operation
*/
AXIS2_DECLARE(axis2_status_t) axis2_thread_once_init(
- axis2_thread_once_t **control, axis2_env_t **env);
+ axis2_thread_once_t **control,
+ axis2_allocator_t *allocator);
/**
* Run the specified function one time, regardless of how many threads
@@ -145,15 +142,14 @@
* @return The status of the operation
*/
AXIS2_DECLARE(axis2_status_t) axis2_thread_once(axis2_thread_once_t *control,
- axis2_env_t **env, void (*func)(void));
+ void (*func)(void));
/**
* detach a thread
* @param thd The thread to detach
* @return The status of the operation
*/
-AXIS2_DECLARE(axis2_status_t) axis2_thread_detach(axis2_thread_t *thd,
- axis2_env_t **env);
+AXIS2_DECLARE(axis2_status_t) axis2_thread_detach(axis2_thread_t *thd);
/** @} */
Added: webservices/axis2/trunk/c/include/axis2_thread_pool.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_thread_pool.h?rev=376693&view=auto
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_thread_pool.h (added)
+++ webservices/axis2/trunk/c/include/axis2_thread_pool.h Fri Feb 10 06:06:36 2006
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef AXIS2_THREAD_POOL_H
+#define AXIS2_THREAD_POOL_H
+
+/**
+ * @file axis2_thread_pool.h
+ * @brief Axis2 thread pool interface
+ */
+
+#include <axis2_defines.h>
+#include <axis2_allocator.h>
+#include <axis2_thread.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @defgroup axis2_thread_pool Thread Pool
+ * @ingroup axis2_util
+ * @{
+ */
+
+typedef struct axis2_thread_pool_ops axis2_thread_pool_ops_t;
+typedef struct axis2_thread_pool axis2_thread_pool_t;
+
+
+/**
+ * \brief Axis2 thread_pool
+ *
+ * Encapsulator for thread pooling routines
+ */
+AXIS2_DECLARE_DATA struct axis2_thread_pool_ops
+{
+ /**
+ * Retrives a thread from the thread pool
+ * @param func function to be executed in the new thread
+ * @param data arguments to be passed to the function
+ * @return pointer to a thread in ready state.
+ */
+ axis2_thread_t * (*get_thread) (axis2_thread_pool_t *pool,
+ axis2_thread_start_t func, void *data);
+ /**
+ * Blocks until the desired thread stops executing.
+ * @param thd The thread to joined
+ * @return status of the operation
+ */
+ axis2_status_t (*join_thread) (axis2_thread_pool_t *pool,
+ axis2_thread_t *thd);
+ /**
+ * Stop the execution of current thread
+ * @param thd thread to be stopped
+ * @return status of the operation
+ */
+ axis2_status_t (*exit_thread) (axis2_thread_pool_t *pool,
+ axis2_thread_t *thd);
+ /**
+ * Detaches a thread
+ * @param thd thread to be detached
+ * @return status of the operation
+ */
+ axis2_status_t (*thread_detach) (axis2_thread_pool_t *pool,
+ axis2_thread_t *thd);
+ /**
+ * Frees resources used by thread_pool
+ * @param pool thread_pool to be freed
+ */
+ axis2_status_t (*free) (axis2_thread_pool_t *pool);
+};
+
+/**
+ * @brief Thread Pool struct
+ * Axis2 Thread Pool
+ */
+AXIS2_DECLARE_DATA struct axis2_thread_pool
+{
+ axis2_thread_pool_ops_t *ops;
+};
+/**
+* Initializes (creates) an thread_pool.
+* @param allocator user defined allocator for the memory allocation.
+* @return initialized thread_pool. NULL on error.
+*/
+AXIS2_DECLARE(axis2_thread_pool_t *) axis2_thread_pool_init(
+ axis2_allocator_t *allocator);
+
+#define AXIS2_THREAD_POOL_GET_THREAD(thread_pool, func, data) \
+ ((thread_pool)->get_thread(thread_pool, func, data))
+#define AXIS2_THREAD_POOL_JOIN_THREAD(thread_pool, thd) \
+ ((thread_pool)->join_thread(thread_pool, thd))
+#define AXIS2_THREAD_POOL_EXIT_THREAD(thread_pool, thd) \
+ ((thread_pool)->exit_thread(thread_pool, thd))
+#define AXIS2_THREAD_POOL_THREAD_DETACH(thread_pool, thd) \
+ ((thread_pool)->thread_detach(thread_pool, thd))
+#define AXIS2_THREAD_POOL_FREE(thread_pool) ((thread_pool)->free(thread_pool))
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AXIS2_THREAD_POOL_H */
Modified: webservices/axis2/trunk/c/modules/util/network_handler.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/network_handler.c?rev=376693&r1=376692&r2=376693&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/network_handler.c (original)
+++ webservices/axis2/trunk/c/modules/util/network_handler.c Fri Feb 10 06:06:36 2006
@@ -98,7 +98,6 @@
axis2_socket_t sock = AXIS2_INVALID_SOCKET;
axis2_socket_t i = 0;
struct sockaddr_in sock_addr;
- int err_code = 0;
AXIS2_ENV_CHECK(env, AXIS2_CRTICAL_FAILURE);
#if defined(WIN32)
Modified: webservices/axis2/trunk/c/modules/util/stream.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/stream.c?rev=376693&r1=376692&r2=376693&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/stream.c (original)
+++ webservices/axis2/trunk/c/modules/util/stream.c Fri Feb 10 06:06:36 2006
@@ -616,7 +616,6 @@
int AXIS2_CALL
axis2_stream_skip_socket (axis2_stream_t *stream, axis2_env_t **env, int count)
{
- axis2_stream_impl_t *stream_impl = NULL;
int len = 0;
char buffer[2];
AXIS2_ENV_CHECK(env, AXIS2_CRTICAL_FAILURE);
Added: webservices/axis2/trunk/c/modules/util/thread_pool.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/thread_pool.c?rev=376693&view=auto
==============================================================================
--- webservices/axis2/trunk/c/modules/util/thread_pool.c (added)
+++ webservices/axis2/trunk/c/modules/util/thread_pool.c Fri Feb 10 06:06:36 2006
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_thread_pool.h>
+
+/**
+ * @brief Stream struct impl
+ * Axis2 Stream impl
+ */
+typedef struct axis2_thread_pool_impl axis2_thread_pool_impl_t;
+
+struct axis2_thread_pool_impl
+{
+ axis2_thread_pool_t thread_pool;
+ axis2_allocator_t *allocator;
+};
+
+#define AXIS2_INTF_TO_IMPL(thread_pool) \
+ ((axis2_thread_pool_impl_t *)(thread_pool))
+
+/********************************Function headers******************************/
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_free (axis2_thread_pool_t *pool);
+
+axis2_thread_t* AXIS2_CALL
+axis2_thread_pool_get_thread (axis2_thread_pool_t *pool,
+ axis2_thread_start_t func, void *data);
+
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_join_thread(axis2_thread_pool_t *pool,
+ axis2_thread_t *thd);
+
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_exit_thread (axis2_thread_pool_t *pool,
+ axis2_thread_t *thd);
+
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_thread_detach (axis2_thread_pool_t *pool,
+ axis2_thread_t *thd);
+
+/************************* End of function headers ****************************/
+AXIS2_DECLARE(axis2_thread_pool_t *)
+axis2_thread_pool_init(axis2_allocator_t *allocator)
+{
+ axis2_thread_pool_impl_t *pool_impl = NULL;
+
+ pool_impl = (axis2_thread_pool_impl_t *)AXIS2_MALLOC(allocator,
+ sizeof(axis2_thread_pool_impl_t));
+
+ if(NULL == pool_impl)
+ {
+ return NULL;
+ }
+ pool_impl->allocator = allocator;
+ pool_impl->thread_pool.ops = (axis2_thread_pool_ops_t *) AXIS2_MALLOC (
+ allocator, sizeof (axis2_thread_pool_ops_t));
+ if (NULL == pool_impl->thread_pool.ops)
+ {
+ axis2_thread_pool_free(&(pool_impl->thread_pool));
+ return NULL;
+ }
+ pool_impl->thread_pool.ops->free = axis2_thread_pool_free;
+ return &(pool_impl->thread_pool);
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_free (axis2_thread_pool_t *pool)
+{
+ axis2_thread_pool_impl_t *pool_impl = NULL;
+ if(NULL == pool)
+ {
+ return AXIS2_FAILURE;
+ }
+ if(NULL == pool_impl->allocator)
+ {
+ return AXIS2_FAILURE;
+ }
+ pool_impl = AXIS2_INTF_TO_IMPL(pool);
+ if (NULL != pool_impl->thread_pool.ops)
+ {
+ AXIS2_FREE (pool_impl->allocator, pool_impl->thread_pool.ops);
+ }
+ AXIS2_FREE(pool_impl->allocator, pool_impl);
+ return AXIS2_SUCCESS;
+}
+
+axis2_thread_t* AXIS2_CALL
+axis2_thread_pool_get_thread (axis2_thread_pool_t *pool,
+ axis2_thread_start_t func, void *data)
+{
+ axis2_thread_pool_impl_t *pool_impl = AXIS2_INTF_TO_IMPL(pool);
+ if(NULL == pool)
+ {
+ return NULL;
+ }
+ if(NULL == pool_impl->allocator)
+ {
+ return NULL;
+ }
+ return axis2_thread_create(pool_impl->allocator, NULL, func, data);
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_join_thread(axis2_thread_pool_t *pool,
+ axis2_thread_t *thd)
+{
+ if(NULL == pool || NULL == thd)
+ {
+ return AXIS2_FAILURE;
+ }
+ return axis2_thread_join(thd);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_exit_thread (axis2_thread_pool_t *pool,
+ axis2_thread_t *thd)
+{
+ if(NULL == pool || NULL == thd)
+ {
+ return AXIS2_FAILURE;
+ }
+ return axis2_thread_exit(thd);
+}
+
+
+axis2_status_t AXIS2_CALL
+axis2_thread_pool_thread_detach (axis2_thread_pool_t *pool,
+ axis2_thread_t *thd)
+{
+ if(NULL == pool || NULL == thd)
+ {
+ return AXIS2_FAILURE;
+ }
+ return axis2_thread_detach(thd);
+}
Modified: webservices/axis2/trunk/c/modules/util/uuid_gen.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/uuid_gen.c?rev=376693&r1=376692&r2=376693&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/uuid_gen.c (original)
+++ webservices/axis2/trunk/c/modules/util/uuid_gen.c Fri Feb 10 06:06:36 2006
@@ -16,9 +16,6 @@
#include <axis2_uuid_gen.h>
-/* We need these static variables to track throughout the program execution */
-static axis2_bool_t axis2_uuid_gen_is_first = AXIS2_TRUE;
-/*static struct axis2_uuid_st axis2_uuid_static;*/
AXIS2_DECLARE(axis2_char_t *)