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 da...@apache.org on 2009/12/18 11:17:49 UTC
svn commit: r892205 - in /webservices/axis2/trunk/c/util:
include/axutil_thread.h include/platforms/windows/axutil_thread_windows.h
src/platforms/unix/thread_unix.c src/platforms/windows/thread_windows.c
Author: damitha
Date: Fri Dec 18 10:17:48 2009
New Revision: 892205
URL: http://svn.apache.org/viewvc?rev=892205&view=rev
Log:
Thread specific storage implementation for unix and windows
Modified:
webservices/axis2/trunk/c/util/include/axutil_thread.h
webservices/axis2/trunk/c/util/include/platforms/windows/axutil_thread_windows.h
webservices/axis2/trunk/c/util/src/platforms/unix/thread_unix.c
webservices/axis2/trunk/c/util/src/platforms/windows/thread_windows.c
Modified: webservices/axis2/trunk/c/util/include/axutil_thread.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/axutil_thread.h?rev=892205&r1=892204&r2=892205&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/axutil_thread.h (original)
+++ webservices/axis2/trunk/c/util/include/axutil_thread.h Fri Dec 18 10:17:48 2009
@@ -140,6 +140,39 @@
);
/**
+ * function is used to allocate a new key. This key now becomes valid for all threads in our process.
+ * When a key is created, the value it points to defaults to NULL. Later on each thread may change
+ * its copy of the value as it wishes.
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axutil_thread_key_create(
+ axutil_threadkey_t * axis2_key);
+ /**
+ * This function is used to get the value of a given key
+ * @return void*. A key's value is simply a void pointer (void*)
+ */
+ AXIS2_EXTERN void *AXIS2_CALL
+ axutil_thread_getspecific(
+ axutil_threadkey_t * axis2_key);
+
+ /**
+ * This function is used to get the value of a given key
+ * @param keys value. A key's value is simply a void pointer (void*), so we can
+ * store in it anything that we want
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axutil_thread_setspecific(
+ axutil_threadkey_t * axis2_key,
+ void *value);
+
+ /**
+ * This function is used free the tls key.
+ */
+ AXIS2_EXTERN void AXIS2_CALL
+ axutil_thread_key_free(
+ axutil_threadkey_t * axis2_key);
+
+ /**
* Initialize the control variable for axutil_thread_once.
* @param control The control variable to initialize
* @return The status of the operation
Modified: webservices/axis2/trunk/c/util/include/platforms/windows/axutil_thread_windows.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/include/platforms/windows/axutil_thread_windows.h?rev=892205&r1=892204&r2=892205&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/include/platforms/windows/axutil_thread_windows.h (original)
+++ webservices/axis2/trunk/c/util/include/platforms/windows/axutil_thread_windows.h Fri Dec 18 10:17:48 2009
@@ -111,6 +111,23 @@
axutil_thread_t * thd,
const axutil_env_t * env);
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_thread_key_create(
+ axutil_threadkey_t * axis2_key);
+
+AXIS2_EXTERN void *AXIS2_CALL
+axutil_thread_getspecific(
+ axutil_threadkey_t * axis2_key);
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_thread_setspecific(
+ axutil_threadkey_t * axis2_key,
+ void *value);
+
+AXIS2_EXTERN void AXIS2_CALL
+axutil_thread_key_free(
+ axutil_threadkey_t * axis2_key);
+
AXIS2_EXTERN axutil_thread_once_t *AXIS2_CALL
axutil_thread_once_init(
axutil_allocator_t * allocator);
Modified: webservices/axis2/trunk/c/util/src/platforms/unix/thread_unix.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/platforms/unix/thread_unix.c?rev=892205&r1=892204&r2=892205&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/platforms/unix/thread_unix.c (original)
+++ webservices/axis2/trunk/c/util/src/platforms/unix/thread_unix.c Fri Dec 18 10:17:48 2009
@@ -220,14 +220,11 @@
*/
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axutil_thread_key_create(
- axutil_threadkey_t * axis2_key,
- void
- (*destructor)(
- void *))
+ axutil_threadkey_t * axis2_key)
{
int rc = -1;
pthread_key_t key = axis2_key->key;
- rc = pthread_key_create(&key, destructor);
+ rc = pthread_key_create(&key, NULL);
if(0 == rc)
return AXIS2_SUCCESS;
else
@@ -267,6 +264,14 @@
return AXIS2_FAILURE;
}
+AXIS2_EXTERN void AXIS2_CALL
+axutil_thread_key_free(
+ axutil_threadkey_t * axis2_key)
+{
+ pthread_key_t key = axis2_key->key;
+ pthread_key_delete(key);
+}
+
AXIS2_EXTERN axis2_os_thread_t *AXIS2_CALL
axis2_os_thread_get(
axutil_thread_t * thd)
Modified: webservices/axis2/trunk/c/util/src/platforms/windows/thread_windows.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/util/src/platforms/windows/thread_windows.c?rev=892205&r1=892204&r2=892205&view=diff
==============================================================================
--- webservices/axis2/trunk/c/util/src/platforms/windows/thread_windows.c (original)
+++ webservices/axis2/trunk/c/util/src/platforms/windows/thread_windows.c Fri Dec 18 10:17:48 2009
@@ -235,6 +235,69 @@
return thd->td;
}
+/**
+ * function is used to allocate a new key. This key now becomes valid for all threads in our process.
+ * When a key is created, the value it points to defaults to NULL. Later on each thread may change
+ * its copy of the value as it wishes.
+ */
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_thread_key_create(
+ axutil_threadkey_t * axis2_key)
+{
+ DWORD tls_key = axis2_key->key;
+ if ((tls_key = TlsAlloc()) == TLS_OUT_OF_INDEXES)
+ {
+ return AXIS2_FAILURE;
+ }
+ else
+ {
+ return AXIS2_SUCCESS;
+ }
+}
+
+/**
+ * This function is used to get the value of a given key
+ * @return void*. A key's value is simply a void pointer (void*)
+ */
+AXIS2_EXTERN void *AXIS2_CALL
+axutil_thread_getspecific(
+ axutil_threadkey_t * axis2_key)
+{
+ void *value = NULL;
+ DWORD tls_key = axis2_key->key;
+ value = TlsGetValue(tls_key);
+ return value;
+}
+
+/**
+ * This function is used to get the value of a given key
+ * @param keys value. A key's value is simply a void pointer (void*), so we can
+ * store in it anything that we want
+ */
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axutil_thread_setspecific(
+ axutil_threadkey_t * axis2_key,
+ void *value)
+{
+ DWORD tls_key = axis2_key->key;
+ if(!TlsSetValue(key, value))
+ {
+ return AXIS2_FAILURE;
+ }
+ else
+ {
+ return AXIS2_SUCCESS;
+ }
+}
+
+AXIS2_EXTERN axis2_void AXIS2_CALL
+axutil_thread_key_free(
+ axutil_threadkey_t * axis2_key)
+{
+ DWORD tls_key = axis2_key->key;
+ TlsFree(tls_key);
+}
+
AXIS2_EXTERN axutil_thread_once_t *AXIS2_CALL
axutil_thread_once_init(
axutil_allocator_t * allocator)