From: Esa Ilari Vuokko Date: Wed, 23 Aug 2006 19:46:04 +0000 (+0000) Subject: Add closeMutex and use it on clean up X-Git-Tag: Before_FC_branch_merge~144 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=88b35c172f9434fd98b700f706074d142914a8bb Add closeMutex and use it on clean up --- diff --git a/includes/OSThreads.h b/includes/OSThreads.h index 9043144..32f147a 100644 --- a/includes/OSThreads.h +++ b/includes/OSThreads.h @@ -161,6 +161,7 @@ extern rtsBool waitCondition ( Condition* pCond, // Mutexes // extern void initMutex ( Mutex* pMut ); +extern void closeMutex ( Mutex* pMut ); // // Thread-local storage diff --git a/rts/Capability.c b/rts/Capability.c index 2384262..e384e1e 100644 --- a/rts/Capability.c +++ b/rts/Capability.c @@ -671,6 +671,9 @@ shutdownCapability (Capability *cap, Task *task) } // we now have the Capability, its run queue and spare workers // list are both empty. + + // We end up here only in THREADED_RTS + closeMutex(&cap->lock); } /* ---------------------------------------------------------------------------- diff --git a/rts/Schedule.c b/rts/Schedule.c index b9b4325..49e25be 100644 --- a/rts/Schedule.c +++ b/rts/Schedule.c @@ -2584,6 +2584,7 @@ exitScheduler( void ) boundTaskExiting(task); stopTaskManager(); } + closeMutex(&sched_mutex); #endif } diff --git a/rts/Stable.c b/rts/Stable.c index 2c4157b..813c6c8 100644 --- a/rts/Stable.c +++ b/rts/Stable.c @@ -169,6 +169,9 @@ exitStablePtrTable(void) stgFree(stable_ptr_table); stable_ptr_table = NULL; SPT_size = 0; +#ifdef THREADED_RTS + closeMutex(&stable_mutex); +#endif } /* diff --git a/rts/Storage.c b/rts/Storage.c index 3594f71..0c9c60e 100644 --- a/rts/Storage.c +++ b/rts/Storage.c @@ -279,6 +279,10 @@ freeStorage (void) stgFree(generations[g].steps); stgFree(generations); freeAllMBlocks(); +#if defined(THREADED_RTS) + closeMutex(&sm_mutex); + closeMutex(&atomic_modify_mutvar_mutex); +#endif } /* ----------------------------------------------------------------------------- diff --git a/rts/Task.c b/rts/Task.c index 3be5b28..a03ed87 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -77,6 +77,10 @@ stopTaskManager (void) for (task = task_free_list; task != NULL; task = next) { next = task->next; stgFree(task); +#if defined(THREADED_RTS) + closeCondition(&task->cond); + closeMutex(&task->lock); +#endif } task_free_list = NULL; RELEASE_LOCK(&sched_mutex); diff --git a/rts/Typeable.c b/rts/Typeable.c index e07c764..4c4d460 100644 --- a/rts/Typeable.c +++ b/rts/Typeable.c @@ -20,7 +20,7 @@ void exitTypeableStore() { #ifdef THREADED_RTS - /* TODO: Free Mutex! */ + closeMutex(&typeableStoreLock); #endif if(typeableStore!=0) { freeStablePtr((StgStablePtr)typeableStore); diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c index cff3782..b30d085 100644 --- a/rts/posix/OSThreads.c +++ b/rts/posix/OSThreads.c @@ -106,6 +106,11 @@ initMutex(Mutex* pMut) #endif return; } +void +closeMutex(Mutex* pMut) +{ + pthread_mutex_destroy(pMut); +} void newThreadLocalKey (ThreadLocalKey *key) diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c index c772be3..00effda 100644 --- a/rts/win32/OSThreads.c +++ b/rts/win32/OSThreads.c @@ -116,6 +116,11 @@ initMutex (Mutex* pMut) { InitializeCriticalSectionAndSpinCount(pMut,4000); } +void +closeMutex (Mutex* pMut) +{ + DeleteCriticalSection(pMut); +} #else void initMutex (Mutex* pMut) @@ -127,6 +132,11 @@ initMutex (Mutex* pMut) *pMut = h; return; } +void +closeMutex (Mutex* pMut) +{ + CloseHandle(*pMut); +} #endif void