Commit 88b35c17 authored by ei@vuokko.info's avatar ei@vuokko.info

Add closeMutex and use it on clean up

parent 52589e05
...@@ -161,6 +161,7 @@ extern rtsBool waitCondition ( Condition* pCond, ...@@ -161,6 +161,7 @@ extern rtsBool waitCondition ( Condition* pCond,
// Mutexes // Mutexes
// //
extern void initMutex ( Mutex* pMut ); extern void initMutex ( Mutex* pMut );
extern void closeMutex ( Mutex* pMut );
// //
// Thread-local storage // Thread-local storage
......
...@@ -671,6 +671,9 @@ shutdownCapability (Capability *cap, Task *task) ...@@ -671,6 +671,9 @@ shutdownCapability (Capability *cap, Task *task)
} }
// we now have the Capability, its run queue and spare workers // we now have the Capability, its run queue and spare workers
// list are both empty. // list are both empty.
// We end up here only in THREADED_RTS
closeMutex(&cap->lock);
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
......
...@@ -2584,6 +2584,7 @@ exitScheduler( void ) ...@@ -2584,6 +2584,7 @@ exitScheduler( void )
boundTaskExiting(task); boundTaskExiting(task);
stopTaskManager(); stopTaskManager();
} }
closeMutex(&sched_mutex);
#endif #endif
} }
......
...@@ -169,6 +169,9 @@ exitStablePtrTable(void) ...@@ -169,6 +169,9 @@ exitStablePtrTable(void)
stgFree(stable_ptr_table); stgFree(stable_ptr_table);
stable_ptr_table = NULL; stable_ptr_table = NULL;
SPT_size = 0; SPT_size = 0;
#ifdef THREADED_RTS
closeMutex(&stable_mutex);
#endif
} }
/* /*
......
...@@ -279,6 +279,10 @@ freeStorage (void) ...@@ -279,6 +279,10 @@ freeStorage (void)
stgFree(generations[g].steps); stgFree(generations[g].steps);
stgFree(generations); stgFree(generations);
freeAllMBlocks(); freeAllMBlocks();
#if defined(THREADED_RTS)
closeMutex(&sm_mutex);
closeMutex(&atomic_modify_mutvar_mutex);
#endif
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
......
...@@ -77,6 +77,10 @@ stopTaskManager (void) ...@@ -77,6 +77,10 @@ stopTaskManager (void)
for (task = task_free_list; task != NULL; task = next) { for (task = task_free_list; task != NULL; task = next) {
next = task->next; next = task->next;
stgFree(task); stgFree(task);
#if defined(THREADED_RTS)
closeCondition(&task->cond);
closeMutex(&task->lock);
#endif
} }
task_free_list = NULL; task_free_list = NULL;
RELEASE_LOCK(&sched_mutex); RELEASE_LOCK(&sched_mutex);
......
...@@ -20,7 +20,7 @@ void ...@@ -20,7 +20,7 @@ void
exitTypeableStore() exitTypeableStore()
{ {
#ifdef THREADED_RTS #ifdef THREADED_RTS
/* TODO: Free Mutex! */ closeMutex(&typeableStoreLock);
#endif #endif
if(typeableStore!=0) { if(typeableStore!=0) {
freeStablePtr((StgStablePtr)typeableStore); freeStablePtr((StgStablePtr)typeableStore);
......
...@@ -106,6 +106,11 @@ initMutex(Mutex* pMut) ...@@ -106,6 +106,11 @@ initMutex(Mutex* pMut)
#endif #endif
return; return;
} }
void
closeMutex(Mutex* pMut)
{
pthread_mutex_destroy(pMut);
}
void void
newThreadLocalKey (ThreadLocalKey *key) newThreadLocalKey (ThreadLocalKey *key)
......
...@@ -116,6 +116,11 @@ initMutex (Mutex* pMut) ...@@ -116,6 +116,11 @@ initMutex (Mutex* pMut)
{ {
InitializeCriticalSectionAndSpinCount(pMut,4000); InitializeCriticalSectionAndSpinCount(pMut,4000);
} }
void
closeMutex (Mutex* pMut)
{
DeleteCriticalSection(pMut);
}
#else #else
void void
initMutex (Mutex* pMut) initMutex (Mutex* pMut)
...@@ -127,6 +132,11 @@ initMutex (Mutex* pMut) ...@@ -127,6 +132,11 @@ initMutex (Mutex* pMut)
*pMut = h; *pMut = h;
return; return;
} }
void
closeMutex (Mutex* pMut)
{
CloseHandle(*pMut);
}
#endif #endif
void void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment