lwp_timer.c revision 51b32bdd07bc63a6e416c5759f0f445147703107
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/lwp_timer_impl.h>
/*
* lwp_timer_timeout() is called from a timeout set up in lwp_cond_wait(),
* lwp_mutex_timedlock(), lwp_sema_timedwait() or lwp_rwlock_lock().
*
* It recomputes the time remaining until the absolute time when the
* wait is supposed to timeout and either calls realtime_timeout()
* to reschedule itself or calls setrun() on the sleeping thread.
*
* This is done to ensure that the waiting thread does not wake up
* due to timer expiration until the absolute future time of the
* timeout has been reached. Until that time, the thread must
* remain on its sleep queue.
*
* An lwp_timer_t structure is used to pass information
* about the sleeping thread to the timeout function.
*/
static void
lwp_timer_timeout(void *arg)
{
mutex_enter(&t->t_delay_lock);
gethrestime(&now);
/*
* Requeue the timeout if no one has reset the system time
* and if the absolute future time has not been reached.
*/
lwptp->lwpt_imm_timeout = 0;
} else {
/*
* Set the thread running only if it is asleep on
* its lwpchan sleep queue (not if it is asleep on
* the t_delay_lock mutex).
*/
thread_lock(t);
/* do this for the benefit of upi mutexes */
(t->t_flag & T_WAKEABLE) &&
setrun_locked(t);
thread_unlock(t);
}
mutex_exit(&t->t_delay_lock);
}
int
{
int error = 0;
goto err;
goto err;
}
} else {
goto err;
}
}
goto err;
}
/*
* Unless the requested timeout is zero,
* get the precise future (absolute) time at
* which we are to time out and return ETIME.
* We must not return ETIME before that time.
*/
} else {
lwptp->lwpt_time_error = 0;
lwptp->lwpt_imm_timeout = 0;
}
return (0);
err:
return (error);
}
int
{
gethrestime(&now);
/*
* Queue the timeout.
*/
lwptp->lwpt_imm_timeout = 0;
return (0);
}
/*
* Time has already run out or someone reset the system time;
* just cause an immediate timeout.
*/
return (1);
}
{
mutex_enter(&t->t_delay_lock);
mutex_exit(&t->t_delay_lock);
mutex_enter(&t->t_delay_lock);
}
mutex_exit(&t->t_delay_lock);
return (tim);
}
int
{
return (error);
gethrestime(&now);
}
}
} else {
}
return (error);
}