Exemplo n.º 1
0
static void
heapcleaner (char *arg)
{
    const void *head;
    struct timeval tv;

    while (1) {

	while ((head = heap_head (heap_ccpairs)) == NULL)
	    LWP_WaitProcess (heap_ccpairs);
	
	while ((head = heap_head (heap_ccpairs)) != NULL) {
	    struct ropa_ccpair *cc = (struct ropa_ccpair *)head;
	    
	    gettimeofday (&tv, NULL);
	    
	    if (tv.tv_sec < cc->expire) {
		unsigned long t = cc->expire - tv.tv_sec;
		IOMGR_Sleep (t);
	    } else {
/* XXX should this be fixed?
		listdel (cc->cb->ccpairs, cc->cb_li);
		cc->cb_li = NULL; */
		break_ccpair (cc, TRUE); /* will remove it from the heap */
	    }
	}
    }
}
Exemplo n.º 2
0
Arquivo: timer.c Projeto: aosm/Heimdal
static void
trigger_jobs(void)
{
    time_t now = time(NULL);

    while (1) {
	struct heim_event_data *e = rk_UNCONST(heap_head(timer_heap));

	if (e != NULL && e->t < now) {
	    heap_remove_head(timer_heap);
	    e->hptr = HEAP_INVALID_PTR;

	    /* if its already running, lets retry 10s from now */
	    if (e->flags & RUNNING) {
		e->t = now + 10;
		heap_insert(timer_heap, e, &e->hptr);
		continue;
	    }
	    e->flags |= RUNNING;

	    _heim_ipc_suspend_timer();

	    dispatch_async(timer_job_q, ^{ 
		    e->callback(e, e->ctx); 
		    dispatch_async(timer_sync_q, ^{
			    e->flags &= ~RUNNING;
			    if (e->running)
				dispatch_semaphore_signal(e->running);

			    _heim_ipc_restart_timer();
			});
		});
Exemplo n.º 3
0
Arquivo: timer.c Projeto: aosm/Heimdal
static void
reschedule_timer(void)
{
    const struct heim_event_data *e = heap_head(timer_heap);

    if (e == NULL) {
	/*
	 * if there are no more events, cancel timer by setting timer
	 * to forever, later calls will pull it down to !forever when
	 * needed again
	 */
	dispatch_source_set_timer(timer_source,
				  DISPATCH_TIME_FOREVER, 0, 10ull * NSEC_PER_SEC);
    } else {
	struct timespec ts;
	ts.tv_sec = e->t;
	ts.tv_nsec = 0;
	dispatch_source_set_timer(timer_source,
				  dispatch_walltime(&ts, 0),
				  0, 10ull * NSEC_PER_SEC);
    }
}