//------------------------------------------------------------------------------
tOplkError timeru_exit(void)
{
    tTimeruData*     pTimer;

    /* cancel thread */
    pthread_cancel(timeruInstance_g.processThread);
    DEBUG_LVL_TIMERU_TRACE("%s() Waiting for thread to exit...\n", __func__);

    /* wait for thread to terminate */
    pthread_join(timeruInstance_g.processThread, NULL);
    DEBUG_LVL_TIMERU_TRACE("%s()Thread exited\n", __func__);

    /* free up timer list */
    resetTimerList();
    while ((pTimer = getNextTimer()) != NULL)
    {
        removeTimer(pTimer);
        OPLK_FREE(pTimer);
    }

    pthread_mutex_destroy(&timeruInstance_g.mutex);

    timeruInstance_g.pFirstTimer = NULL;
    timeruInstance_g.pLastTimer = NULL;

    return kErrorOk;
}
//------------------------------------------------------------------------------
tOplkError timeru_delInstance(void)
{
    ULONG               msg;
    tTimeruData*        pTimer;

    /* send message to timer task to signal shutdown */
    msg = 0;
    msgQSend(timeruInstance_l.msgQueue, (char*)&msg, sizeof(ULONG),
             NO_WAIT, MSG_PRI_NORMAL);

    /* wait for timer task to end */
    while (taskIdVerify(timeruInstance_l.taskId) == OK)
        taskDelay(sysClkRateGet());

    /* free up timer list */
    resetTimerList();
    while ((pTimer = getNextTimer()) != NULL)
    {
        hrtimer_delete (pTimer->timer);
        removeTimer(pTimer);
        OPLK_FREE(pTimer);
    }

    /* cleanup resources */
    semDelete(timeruInstance_l.mutex);
    msgQDelete(timeruInstance_l.msgQueue);

    timeruInstance_l.pFirstTimer = NULL;
    timeruInstance_l.pLastTimer = NULL;

    return kErrorOk;
}