/*
* 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
*/
/*
*/
/*
* Simple implementation of timeout functionality. The granuality is a sec
*/
#include <pthread.h>
#include <stdlib.h>
struct timeval *timeout_time);
typedef struct timeout {
void (*sip_timeout_callback_func)(void *);
int sip_timeout_id;
/*
* LONG_SLEEP_TIME = (24 * 60 * 60 * NANOSEC)
*/
/*
* Invoke the callback function
*/
/* ARGSUSED */
static void *
{
(void) pthread_mutex_lock(&timeout_mutex);
while (timeout_current_start != NULL) {
else
(void) pthread_mutex_unlock(&timeout_mutex);
(void) pthread_mutex_lock(&timeout_mutex);
}
(void) pthread_mutex_unlock(&timeout_mutex);
/* LINTED - suppress E_FUNC_HAS_NO_RETURN_STMT (lint bug 7122677) */
}
/*
* In the very very unlikely case timer id wraps around and we have two timers
* with the same id. If that happens timer with the least amount of time left
* will be deleted. In case both timers have same time left than the one that
* was scheduled first will be deleted as it will be in the front of the list.
*/
{
(void) pthread_mutex_lock(&timeout_mutex);
/*
* Check if this is in the to-be run list
*/
if (timeout_current_start != NULL) {
if (current == timeout_current_start) {
} else {
}
if (current == timeout_current_end)
if (current->sip_timeout_callback_func_arg !=
NULL) {
NULL;
}
break;
}
}
}
/*
* Check if this is in the to-be scheduled list
*/
if (current == timeout_list) {
} else {
}
if (current->sip_timeout_callback_func_arg !=
NULL) {
NULL;
}
break;
}
}
}
(void) pthread_mutex_unlock(&timeout_mutex);
return (ret);
}
/*
* Add a new timeout
*/
struct timeval *timeout_time)
{
#ifdef __linux__
#endif
if (new_timeout == NULL)
return (0);
#ifdef __linux__
return (0);
#else
#endif
if (future_time <= 0L) {
return (0);
}
(void) pthread_mutex_lock(&timeout_mutex);
timer_id++;
if (timer_id == 0)
timer_id++;
} else {
break;
}
}
if (current == timeout_list) {
} else {
}
(void) pthread_cond_signal(&timeout_cond_var);
(void) pthread_mutex_unlock(&timeout_mutex);
return (tid);
}
/*
* Schedule the next timeout
*/
static hrtime_t
{
#ifdef __linux__
#endif
/*
* Thread is holding the mutex.
*/
#ifdef __linux__
#else
current_time = gethrtime();
#endif
if (timeout_list == NULL)
/*
* Get all the timeouts that have fired.
*/
}
if (timeout_current_end != NULL) {
} else {
}
if (create_thread) {
NULL);
(void) pthread_detach(thr);
}
}
if (timeout_list != NULL)
return (timeout_list->sip_timeout_val);
else
}
/*
* The timer routine
*/
/* ARGSUSED */
static void *
{
#ifdef __linux__
#endif
(void) pthread_mutex_lock(&timeout_mutex);
for (;;) {
}
(void) pthread_cond_timedwait(&timeout_cond_var,
&timeout_mutex, &to);
/*
* We return from timedwait because we either timed out
* or a new element was added and we need to reset the time
*/
#ifdef __linux__
goto again; /* ??? */
#else
current_time = gethrtime();
#endif
if (delta <= 0)
goto again;
}
/* NOTREACHED */
return ((void *)0);
}
/*
* The init routine, starts the timer thread
*/
void
{
(void) pthread_mutex_lock(&timeout_mutex);
if (timout_init == B_FALSE) {
(void) pthread_mutex_unlock(&timeout_mutex);
} else {
(void) pthread_mutex_unlock(&timeout_mutex);
return;
}
}