fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * extern variables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global variables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortepthread_mutex_t el_mtx = PTHREAD_MUTEX_INITIALIZER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * local variables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * external variables.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * local functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Shift the indexed-list to the most current time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * t - most current time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (k->time < t) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove the dummy key and dummy notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find the place where the dummy goes to */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update lower bound */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert the dummy key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert the dummy notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* shift the current index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize the element list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * du - Number of uint in the indexed-list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dt - Time interval of the indexed-list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nlim - Limit number of each notice.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: successful, otherwise failed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize the event set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first dummy notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first dummy key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* index list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte il = (el_key_t **)malloc((DU + 1) * sizeof (el_key_t *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create notice list, key list & index list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < DU; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* last dummy notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* last dummy key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* last index */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add an event to the element list with it's execution time.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It might not actually put the event to the list if the event
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is the most current one for execution.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ev - The Event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * t - The time when the event is scheduled at.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * evp - Pointer of event for returning.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - Error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock the event set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* strip it off from the event list which is being handled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if it is rescheduling an event and the event */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* was waiting for execution after idle finishes */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no need to reschedule it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if it is marked as a removed event, do not add it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the index in the il */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* not initialization time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make il up to date */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* avoid overflow */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the last second */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i >= DU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find the right key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (k->time > t) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* need to split */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert a new key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update the key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (y->time > t) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* make a new notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* insert it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (n->time > t) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increase number of notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reset current notice and wake up idle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear event flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "el_add", "%s [%d] is scheduled at %d.",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ev_t *)ev)->type == EV_ESI ? "ESI" : "REG_EXP",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unlock the event set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* failed, free it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ec != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "el_add", "failed, no memory.");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * el_remove:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove or update an event from the element list. If the event is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * currently not in the element list, it must be in a queue which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * contains all of event which are being executing at the moment.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * So it seeks the event from the list prior to the element list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * id1 - The event ID.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * id2 - The second ID for the event update.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pending - Do not actually remove, mark it for removal pending.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - Error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* search the event from the event list which is being handled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* search the notice starting from current */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (n != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* found the match notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!n->isdummy && ev_match(n->event, id1) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update the key of the match notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no more notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (k == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* decrease the count by one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* merge the keys */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* delete the left key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* delete this key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* delete the match notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* update current */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break; /* exit while loop */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fetch the first event from the element list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * t - Pointer of time of the event for returning.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - The event.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove current from the event set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* decrease number of notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* empty not-dummy key */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (k->count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get next notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return the time */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reset current notice */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* the one that is being handled by esi_proc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isnslog(LOG_DEBUG, "el_first", "%s [%d] is fetched.",