Skip to content

Commit 4ad694e

Browse files
committed
Fix for OpenMathLib#2063: The DllMain used in Cygwin did not run the thread memory
pool cleanup upon THREAD_DETACH which is needed when compiled with USE_TLS=1.
1 parent 4fc17d0 commit 4ad694e

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

driver/others/memory.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,13 @@ void blas_memory_free_nolock(void * map_address) {
13131313
free(map_address);
13141314
}
13151315

1316+
#ifdef SMP
1317+
void blas_thread_memory_cleanup(void) {
1318+
blas_memory_cleanup((void*)get_memory_table());
1319+
}
1320+
#endif
1321+
1322+
13161323
void blas_shutdown(void){
13171324
#ifdef SMP
13181325
BLASFUNC(blas_thread_shutdown)();
@@ -1322,7 +1329,7 @@ void blas_shutdown(void){
13221329
/* Only cleanupIf we were built for threading and TLS was initialized */
13231330
if (local_storage_key)
13241331
#endif
1325-
blas_memory_cleanup((void*)get_memory_table());
1332+
blas_thread_memory_cleanup();
13261333

13271334
#ifdef SEEK_ADDRESS
13281335
base_address = 0UL;
@@ -1552,7 +1559,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
15521559
break;
15531560
case DLL_THREAD_DETACH:
15541561
#if defined(SMP)
1555-
blas_memory_cleanup((void*)get_memory_table());
1562+
blas_thread_memory_cleanup();
15561563
#endif
15571564
break;
15581565
case DLL_PROCESS_DETACH:

exports/dllinit.c

+17-7
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,25 @@
4040

4141
void gotoblas_init(void);
4242
void gotoblas_quit(void);
43+
#if defined(SMP) && defined(USE_TLS)
44+
void blas_thread_memory_cleanup(void);
45+
#endif
4346

4447
BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) {
45-
46-
if (reason == DLL_PROCESS_ATTACH) {
47-
gotoblas_init();
48-
}
49-
50-
if (reason == DLL_PROCESS_DETACH) {
51-
gotoblas_quit();
48+
switch(reason) {
49+
case DLL_PROCESS_ATTACH:
50+
gotoblas_init();
51+
break;
52+
case DLL_PROCESS_DETACH:
53+
gotoblas_quit();
54+
break;
55+
case DLL_THREAD_ATTACH:
56+
break;
57+
case DLL_THREAD_DETACH:
58+
#if defined(SMP) && defined(USE_TLS)
59+
blas_thread_memory_cleanup(void);
60+
#endif
61+
break;
5262
}
5363

5464
return TRUE;

0 commit comments

Comments
 (0)