summaryrefslogtreecommitdiff
path: root/sal/osl/w32/thread.c
diff options
context:
space:
mode:
authorHennes Rohling <hro@openoffice.org>2000-09-29 12:46:53 +0000
committerHennes Rohling <hro@openoffice.org>2000-09-29 12:46:53 +0000
commit6bccb9f19e1a4eaaf419de53d8c71726b5d4ca88 (patch)
tree3dfcf1b58e85353936f3610df7d1ec7ed122b71e /sal/osl/w32/thread.c
parent08a3bcd0116bb68d3651da7776f14c035068ade1 (diff)
if thread terminates thread key callback function is called
Diffstat (limited to 'sal/osl/w32/thread.c')
-rw-r--r--sal/osl/w32/thread.c65
1 files changed, 61 insertions, 4 deletions
diff --git a/sal/osl/w32/thread.c b/sal/osl/w32/thread.c
index 1741a2329082..1beff6edc0e5 100644
--- a/sal/osl/w32/thread.c
+++ b/sal/osl/w32/thread.c
@@ -2,9 +2,9 @@
*
* $RCSfile: thread.c,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: hro $ $Date: 2000-09-29 10:56:58 $
+ * last change: $Author: hro $ $Date: 2000-09-29 13:46:53 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -583,8 +583,60 @@ typedef struct _TLS
{
DWORD dwIndex;
oslThreadKeyCallbackFunction pfnCallback;
+ struct _TLS *pNext, *pPrev;
} TLS, *PTLS;
+static PTLS g_pThreadKeyList = NULL;
+
+static void AddKeyToList( PTLS pTls )
+{
+ if ( pTls )
+ {
+ pTls->pNext = g_pThreadKeyList;
+ pTls->pPrev = 0;
+
+ if ( g_pThreadKeyList )
+ g_pThreadKeyList->pPrev = pTls;
+
+ g_pThreadKeyList = pTls;
+ }
+}
+
+static void RemoveKeyFromList( PTLS pTls )
+{
+ if ( pTls )
+ {
+ if ( pTls->pPrev )
+ pTls->pPrev->pNext = pTls->pNext;
+ else
+ {
+ OSL_ASSERT( pTls == g_pThreadKeyList );
+ g_pThreadKeyList = pTls->pNext;
+ }
+
+ if ( pTls->pNext )
+ pTls->pNext->pPrev = pTls->pPrev;
+ }
+}
+
+void SAL_CALL _osl_callThreadKeyCallbackOnThreadDetach()
+{
+ PTLS pTls = g_pThreadKeyList;
+
+ while ( pTls )
+ {
+ if ( pTls->pfnCallback )
+ {
+ void *pValue = TlsGetValue( pTls->dwIndex );
+
+ if ( pValue )
+ pTls->pfnCallback( pValue );
+ }
+
+ pTls = pTls->pNext;
+ }
+}
+
/*****************************************************************************/
/* osl_createThreadKey */
/*****************************************************************************/
@@ -600,7 +652,8 @@ oslThreadKey SAL_CALL osl_createThreadKey(oslThreadKeyCallbackFunction pCallback
rtl_freeMemory( pTls );
pTls = 0;
}
-
+ else
+ AddKeyToList( pTls );
}
return ((oslThreadKey)pTls);
@@ -615,6 +668,7 @@ void SAL_CALL osl_destroyThreadKey(oslThreadKey Key)
{
PTLS pTls = (PTLS)Key;
+ RemoveKeyFromList( pTls );
TlsFree( pTls->dwIndex );
rtl_freeMemory( pTls );
}
@@ -651,7 +705,7 @@ sal_Bool SAL_CALL osl_setThreadKeyData(oslThreadKey Key, void *pData)
fSuccess = TlsSetValue( pTls->dwIndex, pData );
- if ( fSuccess && pTls->pfnCallback )
+ if ( fSuccess && pTls->pfnCallback && pOldData )
pTls->pfnCallback( pOldData );
return (fSuccess != FALSE);
@@ -758,6 +812,9 @@ rtl_TextEncoding SAL_CALL osl_setThreadTextEncoding( rtl_TextEncoding Encoding )
/*************************************************************************
*
* $Log: not supported by cvs2svn $
+* Revision 1.2 2000/09/29 10:56:58 hro
+* osl_createThreadKeyData with callback function paramater, osl_setThreadKeyData works
+*
* Revision 1.1.1.1 2000/09/18 15:17:23 hr
* initial import
*