Example #1
0
static void *main_alarm_handler(void *ctx)
{
    QALARM *q = (QALARM *)ctx;
    QUEUE_ITEM *item;
    pthread_t tid;
    QTHREAD *qt;

    while ((item = Get_Queue_Item(q->queue))) {
        if (!strcmp(item->action, "Terminate")) {

            /* Send termination signal */
            for (qt = q->threads; qt != NULL; qt = qt->next)
                Add_Queue_Item(qt->queue, "Terminate", NULL, 0);

            /* Wait for termination */
            for (qt = q->threads; qt != NULL; qt = qt->next)
                pthread_join(qt->tid, NULL);

            while (q->threads)
                delete_alarm(q, q->threads->tid);

            Free_Queue_Item(item);
            return NULL;
        } else if (!strcmp(item->action, "Wait")) {
            /* Wait for termination */
            for (qt = q->threads; qt != NULL; qt = qt->next)
                pthread_join(qt->tid, NULL);

            while (q->threads)
                delete_alarm(q, q->threads->tid);

            Free_Queue_Item(item);
            return NULL;
        } else if (!strcmp(item->action, "Destroy")) {
            if (item->sz != sizeof(pthread_t)) {
                Free_Queue_Item(item);
                continue;
            }

            pthread_join(*((pthread_t *)(item->data)), NULL);
            delete_alarm(q, *((pthread_t *)(item->data)));
        } else {
            fprintf(stderr, "Unknown action: %s\n", item->action);
        }

        Free_Queue_Item(item);
    }

    return NULL;
}
void del_hs_wake_timer(void)
{
    if(g_hs_wake_timer != 0)
    {
        stop_hs_wake_timer();
        delete_alarm(&g_hs_wake_timer);
        g_hs_wake_timer = 0;
    }
}