Cleaned up driver finish function to make sure resources had been
allocated before they were freed.
This commit is contained in:
parent
9361739244
commit
40393a8e62
1 changed files with 60 additions and 12 deletions
|
@ -353,6 +353,10 @@ DRIVER_INIT(bdberl_drv)
|
||||||
G_LOG_PORT = 0;
|
G_LOG_PORT = 0;
|
||||||
G_LOG_PID = 0;
|
G_LOG_PID = 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DBG("DRIVER INIT FAILED - %s\r\n", db_strerror(G_DB_ENV_ERROR));
|
||||||
|
}
|
||||||
|
|
||||||
return &bdberl_drv_entry;
|
return &bdberl_drv_entry;
|
||||||
}
|
}
|
||||||
|
@ -461,8 +465,17 @@ static void bdberl_drv_stop(ErlDrvData handle)
|
||||||
static void bdberl_drv_finish()
|
static void bdberl_drv_finish()
|
||||||
{
|
{
|
||||||
// Stop the thread pools
|
// Stop the thread pools
|
||||||
|
if (NULL != G_TPOOL_GENERAL)
|
||||||
|
{
|
||||||
bdberl_tpool_stop(G_TPOOL_GENERAL);
|
bdberl_tpool_stop(G_TPOOL_GENERAL);
|
||||||
|
G_TPOOL_GENERAL = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != G_TPOOL_TXNS)
|
||||||
|
{
|
||||||
bdberl_tpool_stop(G_TPOOL_TXNS);
|
bdberl_tpool_stop(G_TPOOL_TXNS);
|
||||||
|
G_TPOOL_TXNS = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Signal the utility threads time is up
|
// Signal the utility threads time is up
|
||||||
G_TRICKLE_ACTIVE = 0;
|
G_TRICKLE_ACTIVE = 0;
|
||||||
|
@ -470,28 +483,63 @@ static void bdberl_drv_finish()
|
||||||
G_CHECKPOINT_ACTIVE = 0;
|
G_CHECKPOINT_ACTIVE = 0;
|
||||||
|
|
||||||
// Close the writer fd on the pipe to signal finish to the utility threads
|
// Close the writer fd on the pipe to signal finish to the utility threads
|
||||||
|
if (-1 != G_BDBERL_PIPE[1])
|
||||||
|
{
|
||||||
close(G_BDBERL_PIPE[1]);
|
close(G_BDBERL_PIPE[1]);
|
||||||
G_BDBERL_PIPE[1] = -1;
|
G_BDBERL_PIPE[1] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for the deadlock checker to shutdown -- then wait for it
|
// Wait for the deadlock checker to shutdown -- then wait for it
|
||||||
|
if (0 != G_DEADLOCK_THREAD)
|
||||||
|
{
|
||||||
erl_drv_thread_join(G_DEADLOCK_THREAD, 0);
|
erl_drv_thread_join(G_DEADLOCK_THREAD, 0);
|
||||||
|
G_DEADLOCK_THREAD = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for the checkpointer to shutdown -- then wait for it
|
// Wait for the checkpointer to shutdown -- then wait for it
|
||||||
|
if (0 != G_CHECKPOINT_THREAD)
|
||||||
|
{
|
||||||
erl_drv_thread_join(G_CHECKPOINT_THREAD, 0);
|
erl_drv_thread_join(G_CHECKPOINT_THREAD, 0);
|
||||||
|
G_CHECKPOINT_THREAD = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Close the reader fd on the pipe now utility threads are closed
|
// Close the reader fd on the pipe now utility threads are closed
|
||||||
|
if (-1 != G_BDBERL_PIPE[0])
|
||||||
|
{
|
||||||
close(G_BDBERL_PIPE[0]);
|
close(G_BDBERL_PIPE[0]);
|
||||||
|
}
|
||||||
G_BDBERL_PIPE[0] = -1;
|
G_BDBERL_PIPE[0] = -1;
|
||||||
|
|
||||||
// Cleanup and shut down the BDB environment. Note that we assume
|
// Cleanup and shut down the BDB environment. Note that we assume
|
||||||
// all ports have been released and thuse all databases/txns/etc are also gone.
|
// all ports have been released and thuse all databases/txns/etc are also gone.
|
||||||
|
if (NULL != G_DB_ENV)
|
||||||
|
{
|
||||||
G_DB_ENV->close(G_DB_ENV, 0);
|
G_DB_ENV->close(G_DB_ENV, 0);
|
||||||
|
G_DB_ENV = NULL;
|
||||||
|
}
|
||||||
|
if (NULL != G_DATABASES)
|
||||||
|
{
|
||||||
driver_free(G_DATABASES);
|
driver_free(G_DATABASES);
|
||||||
|
G_DATABASES = NULL;
|
||||||
|
}
|
||||||
|
if (NULL != G_DATABASES_RWLOCK)
|
||||||
|
{
|
||||||
erl_drv_rwlock_destroy(G_DATABASES_RWLOCK);
|
erl_drv_rwlock_destroy(G_DATABASES_RWLOCK);
|
||||||
|
G_DATABASES_RWLOCK = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != G_DATABASES_NAMES)
|
||||||
|
{
|
||||||
hive_hash_destroy(G_DATABASES_NAMES);
|
hive_hash_destroy(G_DATABASES_NAMES);
|
||||||
|
G_DATABASES_NAMES = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Release the logging rwlock
|
// Release the logging rwlock
|
||||||
|
if (NULL != G_LOG_RWLOCK)
|
||||||
|
{
|
||||||
erl_drv_rwlock_destroy(G_LOG_RWLOCK);
|
erl_drv_rwlock_destroy(G_LOG_RWLOCK);
|
||||||
|
G_LOG_RWLOCK = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
DBG("DRIVER_FINISH\n");
|
DBG("DRIVER_FINISH\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue