/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include "isns_server.h"
#include "isns_protocol.h"
#include "isns_log.h"
#include "isns_sched.h"
#include "isns_scn.h"
#include "isns_esi.h"
/*
* extern variables.
*/
/*
* global variables.
*/
/*
* local variables.
*/
static int icurr = 0;
/*
* external variables.
*/
/*
* local functions.
*/
/*
* ****************************************************************************
*
* il_shift:
* Shift the indexed-list to the most current time.
*
* t - most current time.
*
* ****************************************************************************
*/
static void
uint32_t t
)
{
int c;
while (k->time < t) {
fk = k;
/* remove the dummy key and dummy notice */
/* find the place where the dummy goes to */
} else {
}
k = k->right;
}
c = 1;
c ++;
n = n->pred;
}
n = n->sucd;
/* update lower bound */
/* insert the dummy key */
k->count = c;
/* insert the dummy notice */
/* shift the current index */
}
}
/*
* global functions.
*/
/*
* ****************************************************************************
*
* el_init:
* Initialize the element list.
*
* du - Number of uint in the indexed-list.
* dt - Time interval of the indexed-list.
* nlim - Limit number of each notice.
* return - 0: successful, otherwise failed.
*
* ****************************************************************************
*/
int
)
{
uint32_t t = 0;
int i;
return (1);
}
LB = 0;
/*
* initialize the event set
*/
/* first dummy notice */
if (n == NULL) {
return (1);
}
n->isdummy = 1;
npred = n;
/* first dummy key */
if (k == NULL) {
return (1);
}
k->count = 1;
k->notice = n;
kleft = k;
n->key = k;
/* index list */
return (1);
}
/* create notice list, key list & index list */
for (i = 0; i < DU; i++) {
t += DT;
if (n == NULL) {
return (1);
}
n->time = t;
n->isdummy = 1;
npred = n;
if (k == NULL) {
return (1);
}
k->time = t;
k->count = 1;
k->notice = n;
kleft = k;
n->key = k;
il[i] = k;
}
/* last dummy notice */
if (n == NULL) {
return (1);
}
n->isdummy = 1;
/* last dummy key */
if (k == NULL) {
return (1);
}
k->count = 1;
k->notice = n;
n->key = k;
/* last index */
return (0);
}
/*
* ****************************************************************************
*
* el_add:
* Add an event to the element list with it's execution time.
* It might not actually put the event to the list if the event
* is the most current one for execution.
*
* ev - The Event.
* t - The time when the event is scheduled at.
* evp - Pointer of event for returning.
* return - Error code.
*
* ****************************************************************************
*/
int
void *ev,
uint32_t t,
void **evp
)
{
int ec = 0;
int i, j;
el_key_t *k;
el_notice_t *n;
el_key_t *y;
el_notice_t *x;
/* lock the event set */
(void) pthread_mutex_lock(&el_mtx);
/* strip it off from the event list which is being handled */
/* if it is rescheduling an event and the event */
/* was waiting for execution after idle finishes */
/* no need to reschedule it */
goto add_done;
}
/* if it is marked as a removed event, do not add it */
goto add_done;
}
}
/* get the index in the il */
if (t == 0) {
/* not initialization time */
/* make il up to date */
/* avoid overflow */
/* the last second */
}
}
t += t1;
}
if (i >= DU) {
i = DU;
} else {
}
/* find the right key */
while (k->time > t) {
k = k->left;
}
k = k->right;
/* need to split */
/* insert a new key */
if (y == NULL) {
goto add_done;
}
x = k->notice;
x = x->pred;
}
y->notice = x;
y->right = k;
k->left = y;
/* update the key */
x->key = y;
/* shift */
if (y->time > t) {
k = y;
}
}
/* make a new notice */
if (x == NULL) {
goto add_done;
}
x->time = t;
x->isdummy = 0;
/* insert it */
n = k->notice;
while (n->time > t) {
n = n->pred;
}
x->pred = n;
n->sucd = x;
/* increase number of notice */
k->count ++;
/* reset current notice and wake up idle */
curr = x;
}
/* clear event flags */
t);
/* unlock the event set */
(void) pthread_mutex_unlock(&el_mtx);
/* failed, free it */
if (ec != 0) {
}
return (ec);
}
/*
* ****************************************************************************
*
* el_remove:
* Remove or update an event from the element list. If the event is
* currently not in the element list, it must be in a queue which
* contains all of event which are being executing at the moment.
* So it seeks the event from the list prior to the element list.
*
* id1 - The event ID.
* id2 - The second ID for the event update.
* pending - Do not actually remove, mark it for removal pending.
* return - Error code.
*
* ****************************************************************************
*/
int
int pending
)
{
(void) pthread_mutex_lock(&el_mtx);
/* search the event from the event list which is being handled */
(void) pthread_mutex_unlock(&el_mtx);
return (0);
}
/* search the notice starting from current */
n = curr;
while (n != NULL) {
/* found the match notice */
/* update the key of the match notice */
k = n->key;
/* no more notice */
free(k);
} else {
if (k != NULL) {
}
n2 = n;
while (k == NULL) {
}
/* decrease the count by one */
k->count --;
/* merge the keys */
/* delete the left key */
/* delete this key */
free(k);
}
}
/* delete the match notice */
/* update current */
if (n == curr) {
}
}
free(n);
}
break; /* exit while loop */
}
n = n->sucd;
}
(void) pthread_mutex_unlock(&el_mtx);
return (0);
}
/*
* ****************************************************************************
*
* el_first:
* Fetch the first event from the element list.
*
* t - Pointer of time of the event for returning.
* return - The event.
*
* ****************************************************************************
*/
void *
uint32_t *t
)
{
void *p = NULL;
el_notice_t *n;
el_key_t *k;
(void) pthread_mutex_lock(&el_mtx);
/* remove current from the event set */
/* decrease number of notice */
n = curr;
n = n->sucd;
}
k = n->key;
k->count --;
/* empty not-dummy key */
if (k->count == 0) {
free(k);
}
/* get next notice */
n = n->sucd;
}
/* return the time */
/* reset current notice */
curr = n;
}
/* the one that is being handled by esi_proc */
if (p) {
evl_append(p);
}
(void) pthread_mutex_unlock(&el_mtx);
if (p) {
}
return (p);
}