sip_timeout.c revision 2
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * CDDL HEADER START
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * The contents of this file are subject to the terms of the
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * Common Development and Distribution License (the "License").
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * You may not use this file except in compliance with the License.
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * See the License for the specific language governing permissions
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * and limitations under the License.
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * When distributing Covered Code, include this CDDL HEADER in each
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * If applicable, add the following below this CDDL HEADER, with the
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * fields enclosed by brackets "[]" replaced with your own identifying
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * information: Portions Copyright [yyyy] [name of copyright owner]
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * CDDL HEADER END
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * Simple implementation of timeout functionality. The granuality is a sec
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppneruint_t sip_timeout(void *arg, void (*callback_func)(void *),
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppnertypedef struct timeout {
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppnerstatic pthread_mutex_t timeout_mutex = PTHREAD_MUTEX_INITIALIZER;
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppnerstatic pthread_cond_t timeout_cond_var = PTHREAD_COND_INITIALIZER;
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * LONG_SLEEP_TIME = (24 * 60 * 60 * NANOSEC)
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner#define LONG_SLEEP_TIME (0x15180LL * 0x3B9ACA00LL)
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * Invoke the callback function
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner/* ARGSUSED */
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner if (timeout_current_end == timeout_current_start)
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner timeout_current_start = timeout_current_end = NULL;
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner timeout_current_start = timeout->sip_timeout_next;
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner /* LINTED - suppress E_FUNC_HAS_NO_RETURN_STMT (lint bug 7122677) */
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * In the very very unlikely case timer id wraps around and we have two timers
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * with the same id. If that happens timer with the least amount of time left
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * will be deleted. In case both timers have same time left than the one that
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * was scheduled first will be deleted as it will be in the front of the list.
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * Check if this is in the to-be run list
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * Check if this is in the to-be scheduled list
5e989a96186a37eb528fb7bb4d28a150874ec799David Höppner * Add a new timeout
#ifdef __linux__
#ifdef __linux__
if (future_time <= 0L) {
timer_id++;
if (timer_id == 0)
timer_id++;
return (tid);
static hrtime_t
#ifdef __linux__
#ifdef __linux__
if (create_thread) {
NULL);
#ifdef __linux__
#ifdef __linux__
if (delta <= 0)
goto again;