summaryrefslogtreecommitdiff
path: root/sal
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
parent08a3bcd0116bb68d3651da7776f14c035068ade1 (diff)
if thread terminates thread key callback function is called
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/w32/dllentry.c152
-rw-r--r--sal/osl/w32/thread.c65
2 files changed, 141 insertions, 76 deletions
diff --git a/sal/osl/w32/dllentry.c b/sal/osl/w32/dllentry.c
index 57389013ea5e..9409016eda0e 100644
--- a/sal/osl/w32/dllentry.c
+++ b/sal/osl/w32/dllentry.c
@@ -2,9 +2,9 @@
*
* $RCSfile: dllentry.c,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: hr $ $Date: 2000-09-18 15:17:23 $
+ * 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
@@ -68,6 +68,9 @@
#include <systools/win32/comdlg9x.h>
#include <systools/win32/user9x.h>
+#include <osl/diagnose.h>
+#include <sal/types.h>
+
#define _DIRW9X_INITIALIZE_
#include "dirW9X.h"
@@ -76,12 +79,11 @@ extern HRESULT (WINAPI *_CoInitializeEx) (LPVOID pvReserved, DWORD dwCoInit);
extern LPWSTR *lpArgvW;
extern DWORD g_dwTLSTextEncodingIndex;
+extern void SAL_CALL _osl_callThreadKeyCallbackOnThreadDetach(void);
/* remember plattform */
DWORD g_dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
-#include <osl/diagnose.h>
-
#define ERR_GENERAL_WRONG_CPU 101
#define ERR_WINSOCK_INIT_FAILED 102
#define ERR_WINSOCK_WRONG_VERSION 103
@@ -133,90 +135,96 @@ __declspec( dllexport ) sal_Bool WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwRea
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
- {
- OSVERSIONINFO aInfo;
- WORD wVersionRequested;
- WSADATA wsaData;
- int error;
+ {
+ OSVERSIONINFO aInfo;
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int error;
#ifdef _M_IX86
- SYSTEM_INFO SystemInfo;
+ SYSTEM_INFO SystemInfo;
- GetSystemInfo(&SystemInfo);
+ GetSystemInfo(&SystemInfo);
- if ((SystemInfo.dwProcessorType != PROCESSOR_INTEL_486) &&
- (SystemInfo.dwProcessorType != PROCESSOR_INTEL_PENTIUM))
- showMessage(ERR_GENERAL_WRONG_CPU);
+ if ((SystemInfo.dwProcessorType != PROCESSOR_INTEL_486) &&
+ (SystemInfo.dwProcessorType != PROCESSOR_INTEL_PENTIUM))
+ showMessage(ERR_GENERAL_WRONG_CPU);
#endif
- wVersionRequested = MAKEWORD(2, 2);
+ wVersionRequested = MAKEWORD(2, 2);
- error = WSAStartup(wVersionRequested, &wsaData);
- if (error == 0)
- {
- WORD wMajorVersionRequired = 1;
- WORD wMinorVersionRequired = 1;
-
- if ((LOBYTE(wsaData.wVersion) < wMajorVersionRequired) ||
- (LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
- ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired)))
- showMessage(ERR_WINSOCK_WRONG_VERSION);
- }
- else
- showMessage(ERR_WINSOCK_INIT_FAILED);
+ error = WSAStartup(wVersionRequested, &wsaData);
+ if (error == 0)
+ {
+ WORD wMajorVersionRequired = 1;
+ WORD wMinorVersionRequired = 1;
- /* initialize Win9x unicode functions */
- aInfo.dwOSVersionInfoSize = sizeof(aInfo);
- if (GetVersionEx(&aInfo))
- {
- Kernel9xInit(&aInfo);
- Advapi9xInit(&aInfo);
- Comdlg9xInit(&aInfo);
- Shell9xInit(&aInfo);
- User9xInit(&aInfo);
+ if ((LOBYTE(wsaData.wVersion) < wMajorVersionRequired) ||
+ (LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
+ ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired)))
+ showMessage(ERR_WINSOCK_WRONG_VERSION);
+ }
+ else
+ showMessage(ERR_WINSOCK_INIT_FAILED);
- if (aInfo.dwPlatformId==VER_PLATFORM_WIN32_NT)
+ /* initialize Win9x unicode functions */
+ aInfo.dwOSVersionInfoSize = sizeof(aInfo);
+ if (GetVersionEx(&aInfo))
{
- lpfnFindFirstFile = FindFirstFileW;
- lpfnFindNextFile = FindNextFileW;
- lpfnCreateFile = CreateFileW;
- lpfnSetFileAttributes = SetFileAttributesW;
- lpfnSearchPath = SearchPathW;
- lpfnCreateProcess = CreateProcessW;
- lpfnCreateProcessAsUser = CreateProcessAsUserW;
- lpfnGetEnvironmentVariable=GetEnvironmentVariableW;
- lpfnWNetAddConnection2=WNetAddConnection2W;
- lpfnWNetCancelConnection2=WNetCancelConnection2W;
- lpfnWNetGetUser=WNetGetUserW;
- lpfnGetWindowsDirectory=GetWindowsDirectoryW;
- lpfnCreateDirectory=CreateDirectoryW;
- lpfnWritePrivateProfileString=WritePrivateProfileStringW;
- lpfnGetPrivateProfileString=GetPrivateProfileStringW;
+ Kernel9xInit(&aInfo);
+ Advapi9xInit(&aInfo);
+ Comdlg9xInit(&aInfo);
+ Shell9xInit(&aInfo);
+ User9xInit(&aInfo);
+
+ if (aInfo.dwPlatformId==VER_PLATFORM_WIN32_NT)
+ {
+ lpfnFindFirstFile = FindFirstFileW;
+ lpfnFindNextFile = FindNextFileW;
+ lpfnCreateFile = CreateFileW;
+ lpfnSetFileAttributes = SetFileAttributesW;
+ lpfnSearchPath = SearchPathW;
+ lpfnCreateProcess = CreateProcessW;
+ lpfnCreateProcessAsUser = CreateProcessAsUserW;
+ lpfnGetEnvironmentVariable=GetEnvironmentVariableW;
+ lpfnWNetAddConnection2=WNetAddConnection2W;
+ lpfnWNetCancelConnection2=WNetCancelConnection2W;
+ lpfnWNetGetUser=WNetGetUserW;
+ lpfnGetWindowsDirectory=GetWindowsDirectoryW;
+ lpfnCreateDirectory=CreateDirectoryW;
+ lpfnWritePrivateProfileString=WritePrivateProfileStringW;
+ lpfnGetPrivateProfileString=GetPrivateProfileStringW;
+ }
+
+ g_dwPlatformId = aInfo.dwPlatformId;
}
- g_dwPlatformId = aInfo.dwPlatformId;
- }
+ g_dwTLSTextEncodingIndex = TlsAlloc();
- g_dwTLSTextEncodingIndex = TlsAlloc();
+ // InitDCOM();
-// InitDCOM();
-
- break;
- }
+ break;
+ }
case DLL_PROCESS_DETACH:
- {
- Advapi9xDeInit();
- Comdlg9xDeInit();
- Kernel9xDeInit();
- Shell9xDeInit();
- User9xDeInit();
-
- WSACleanup();
- if (lpArgvW)
- GlobalFree(lpArgvW);
+ {
+ Advapi9xDeInit();
+ Comdlg9xDeInit();
+ Kernel9xDeInit();
+ Shell9xDeInit();
+ User9xDeInit();
+
+ WSACleanup();
+ if (lpArgvW)
+ GlobalFree(lpArgvW);
+ break;
+
+ TlsFree( g_dwTLSTextEncodingIndex );
+ }
+ case DLL_THREAD_ATTACH:
break;
- TlsFree( g_dwTLSTextEncodingIndex );
- }
+ case DLL_THREAD_DETACH:
+ _osl_callThreadKeyCallbackOnThreadDetach();
+ break;
}
return (sal_True);
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
*