fmd_timerq.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <signal.h>
#include <strings.h>
#include <limits.h>
#include <fmd_alloc.h>
#include <fmd_subr.h>
#include <fmd_thread.h>
#include <fmd_timerq.h>
#include <fmd.h>
/*
* Install a new timer to fire after at least 'delta' nanoseconds have elapsed.
* Timers are associated with persistent integer identifiers in some idspace.
* We allocate a new timer structure or re-use one from our freelist, and then
* place it on the queue's list in sorted order by expiration time. If the new
* timer is now the earliest to expire, we awaken the fmd_timerq_exec() thread.
*/
{
} else
return (id);
}
if (delta < 0)
delta = 0; /* ensure delta is at least 0ns from now */
else
/*
* For now we use a simple insertion sort for tmq_list. If we have
* scaling problems here due to heavy use of our timer subsystem,
* then tmq_list can and should be replaced with a O(logN) heap.
*/
break;
}
else
return (id);
}
/*
* Remove the specified timer. If the 'id' is invalid, we'll panic inside of
* fmd_idspace_free(). If the timer is still set, we move it to the freelist
* and update the timer thread as needed. If the timer 'id' is valid but
* tmr_id is not equal to id, then the timer callback is running: we wait for
* tmr_id to change to zero (indicating tmr_func is done) before returning.
*/
void *
{
return (NULL); /* timer is no longer active */
}
/*
* If tmq_list is now empty, we must awaken the exec thread so
* it will sleep on tmq_cv waiting for the list to change. We
* could also awaken the exec thread if we removed the head of
* tmq_list, but an early wakeup is harmless so we do nothing.
*/
} else {
/*
* Wait until tmr_id is zero, indicating that tmr_func is done.
* This relies on expired fmd_timer_t's being returned to our
* free list rather than having the data structure deallocated.
*/
}
return (arg);
}
/*
* fmd_timerq_exec() is the main loop of the thread that runs the timer queue.
* We sleep on tmq_cv waiting for timers to show up on tmq_list. When the list
* is non-empty, we execute the callback function for each expired timer. If
* timers remain that are not yet expired, we nanosleep() until the next expiry
* time. We awaken whenever nanosleep() expires or we are interrupted by a
* SIGALRM from fmd_timerq_install indicating that we need to rescan our list.
*/
static void
{
/*
* fmd_thread_create() initializes threads with all signals blocked.
* We must unblock SIGALRM (whose disposition has been to set to call
* an empty function by fmd_timerq_init()) in order to permit directed
* signals to interrupt our nanosleep() and make it return EINTR.
* This SIGALRM mechanism is used by the native clock (see fmd_time.c).
*/
(void) sigemptyset(&set);
for (;;) {
return; /* abort timerq thread */
}
break; /* no more timers left to expire */
}
}
}
}
static void
fmd_timerq_alrm(int sig)
{
}
fmd_timerq_create(void)
{
fmd_panic("failed to create timer thread");
return (tmq);
}
void
{
else
}
}
}