Skip to content

Commit 8502030

Browse files
authored
Merge pull request #2064 from embray/cygwin/use-tls-thread-memory-cleanup
Fix for #2063
2 parents dff4a19 + 8ba9e2a commit 8502030

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

driver/others/blas_server_win32.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,18 @@ int BLASFUNC(blas_thread_shutdown)(void){
461461
SetEvent(pool.killed);
462462

463463
for(i = 0; i < blas_num_threads - 1; i++){
464+
// Could also just use WaitForMultipleObjects
464465
WaitForSingleObject(blas_threads[i], 5); //INFINITE);
465466
#ifndef OS_WINDOWSSTORE
466467
// TerminateThread is only available with WINAPI_DESKTOP and WINAPI_SYSTEM not WINAPI_APP in UWP
467468
TerminateThread(blas_threads[i],0);
468469
#endif
470+
CloseHandle(blas_threads[i]);
469471
}
470472

473+
CloseHandle(pool.filled);
474+
CloseHandle(pool.killed);
475+
471476
blas_server_avail = 0;
472477
}
473478

driver/others/memory.c

Lines changed: 9 additions & 2 deletions
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

Lines changed: 17 additions & 7 deletions
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();
60+
#endif
61+
break;
5262
}
5363

5464
return TRUE;

0 commit comments

Comments
 (0)