[Libreoffice-commits] .: sal/inc sal/osl sal/qa
Caolán McNamara
caolan at kemper.freedesktop.org
Mon Jun 20 08:54:42 PDT 2011
sal/inc/osl/thread.h | 2 -
sal/osl/unx/thread.c | 49 ++++++++++++++++++++++++++++++++------
sal/qa/osl/process/osl_Thread.cxx | 5 ---
3 files changed, 43 insertions(+), 13 deletions(-)
New commits:
commit 01fae8d04e8b8980b547ed88ba15a52e92e7b4f7
Author: Caolán McNamara <caolanm at redhat.com>
Date: Mon Jun 20 16:53:43 2011 +0100
make pthreads osl_setThreadKeyData backend work the same on all OSes
diff --git a/sal/inc/osl/thread.h b/sal/inc/osl/thread.h
index 4cd058b..9e088e6 100644
--- a/sal/inc/osl/thread.h
+++ b/sal/inc/osl/thread.h
@@ -68,7 +68,7 @@ typedef enum
typedef sal_uInt32 oslThreadIdentifier;
-typedef sal_uInt32 oslThreadKey;
+typedef void* oslThreadKey;
/** Create the thread, using the function-ptr pWorker as
its main (worker) function. This functions receives in
diff --git a/sal/osl/unx/thread.c b/sal/osl/unx/thread.c
index 06730ac..b11edb0 100644
--- a/sal/osl/unx/thread.c
+++ b/sal/osl/unx/thread.c
@@ -35,6 +35,7 @@
#include <osl/thread.h>
#include <osl/nlsupport.h>
#include <rtl/textenc.h>
+#include <rtl/alloc.h>
#include <sal/macros.h>
#if defined LINUX
@@ -975,17 +976,31 @@ oslThreadPriority SAL_CALL osl_getThreadPriority(const oslThread Thread)
return Priority;
}
+typedef struct _wrapper_pthread_key
+{
+ pthread_key_t m_key;
+ oslThreadKeyCallbackFunction pfnCallback;
+} wrapper_pthread_key;
+
/*****************************************************************************/
/* osl_createThreadKey */
/*****************************************************************************/
oslThreadKey SAL_CALL osl_createThreadKey( oslThreadKeyCallbackFunction pCallback )
{
- pthread_key_t key;
+ wrapper_pthread_key *pKey = (wrapper_pthread_key*)rtl_allocateMemory(sizeof(wrapper_pthread_key));
+
+ if (pKey)
+ {
+ pKey->pfnCallback = pCallback;
- if (pthread_key_create(&key, pCallback) != 0)
- key = 0;
+ if (pthread_key_create(&(pKey->m_key), pKey->pfnCallback) != 0)
+ {
+ rtl_freeMemory(pKey);
+ pKey = 0;
+ }
+ }
- return ((oslThreadKey)key);
+ return ((oslThreadKey)pKey);
}
/*****************************************************************************/
@@ -993,7 +1008,12 @@ oslThreadKey SAL_CALL osl_createThreadKey( oslThreadKeyCallbackFunction pCallbac
/*****************************************************************************/
void SAL_CALL osl_destroyThreadKey(oslThreadKey Key)
{
- pthread_key_delete((pthread_key_t)Key);
+ wrapper_pthread_key *pKey = (wrapper_pthread_key*)Key;
+ if (pKey)
+ {
+ pthread_key_delete(pKey->m_key);
+ rtl_freeMemory(pKey);
+ }
}
/*****************************************************************************/
@@ -1001,7 +1021,8 @@ void SAL_CALL osl_destroyThreadKey(oslThreadKey Key)
/*****************************************************************************/
void* SAL_CALL osl_getThreadKeyData(oslThreadKey Key)
{
- return (pthread_getspecific((pthread_key_t)Key));
+ wrapper_pthread_key *pKey = (wrapper_pthread_key*)Key;
+ return pKey ? pthread_getspecific(pKey->m_key) : NULL;
}
/*****************************************************************************/
@@ -1009,7 +1030,21 @@ void* SAL_CALL osl_getThreadKeyData(oslThreadKey Key)
/*****************************************************************************/
sal_Bool SAL_CALL osl_setThreadKeyData(oslThreadKey Key, void *pData)
{
- return (pthread_setspecific((pthread_key_t)Key, pData) == 0);
+ sal_Bool bRet;
+ void *pOldData = NULL;
+ wrapper_pthread_key *pKey = (wrapper_pthread_key*)Key;
+ if (!pKey)
+ return sal_False;
+
+ if (pKey->pfnCallback)
+ pOldData = pthread_getspecific(pKey->m_key);
+
+ bRet = (pthread_setspecific(pKey->m_key, pData) == 0);
+
+ if (bRet && pKey->pfnCallback && pOldData)
+ pKey->pfnCallback(pOldData);
+
+ return bRet;
}
/*****************************************************************************/
diff --git a/sal/qa/osl/process/osl_Thread.cxx b/sal/qa/osl/process/osl_Thread.cxx
index aa6ad67..0def479 100644
--- a/sal/qa/osl/process/osl_Thread.cxx
+++ b/sal/qa/osl/process/osl_Thread.cxx
@@ -2099,9 +2099,6 @@ namespace osl_ThreadData
"ThreadData setData: ",
cData1 == 'a' && cData2 == 'b' && aChar == 'o'
);
-
- delete [] pc2;
- delete [] pc;
}
CPPUNIT_TEST_SUITE(setData);
@@ -2149,8 +2146,6 @@ namespace osl_ThreadData
"ThreadData setData: ",
cData1 == 'c' && cData2 == 'd' && aChar == 'i'
);
-
- delete [] pc;
}
// setData then change the value in the address data pointer points,
More information about the Libreoffice-commits
mailing list