diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-06-20 16:53:43 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-06-20 16:53:43 +0100 |
commit | 01fae8d04e8b8980b547ed88ba15a52e92e7b4f7 (patch) | |
tree | 0a06347491067f91c3221a5f7ae3a95ecf411d10 /sal | |
parent | c033fb056371181c178f5b53d715c209436bfece (diff) |
make pthreads osl_setThreadKeyData backend work the same on all OSes
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/osl/thread.h | 2 | ||||
-rw-r--r-- | sal/osl/unx/thread.c | 49 | ||||
-rw-r--r-- | sal/qa/osl/process/osl_Thread.cxx | 5 |
3 files changed, 43 insertions, 13 deletions
diff --git a/sal/inc/osl/thread.h b/sal/inc/osl/thread.h index 4cd058b28..9e088e6e4 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 06730acb2..b11edb0e2 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 aa6ad6726..0def479d9 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, |