1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997,2008 Oracle.  All rights reserved.
5 *
6 * $Id: os_vx_yield.c,v 1.6 2008/01/08 20:58:45 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13/*
14 * __os_yield --
15 *	Yield the processor, optionally pausing until running again.
16 */
17void
18__os_yield(env, secs, usecs)
19	ENV *env;
20	u_long secs, usecs;		/* Seconds and microseconds. */
21{
22	int ticks_delay, ticks_per_second;
23
24	COMPQUIET(env, NULL);
25
26	/* Don't require the values be normalized. */
27	for (; usecs >= US_PER_SEC; usecs -= US_PER_SEC)
28		++secs;
29
30	/*
31	 * Yield the processor so other processes or threads can run.
32	 *
33	 * As a side effect, taskDelay() moves the calling task to the end of
34	 * the ready queue for tasks of the same priority. In particular, you
35	 * can yield the CPU to any other tasks of the same priority by
36	 * "delaying" for zero clock ticks.
37	 *
38	 * Never wait less than a tick, if we were supposed to wait at all.
39	 */
40	ticks_per_second = sysClkRateGet();
41	ticks_delay =
42	    secs * ticks_per_second + (usecs * ticks_per_second) / US_PER_SEC;
43	if (ticks_delay == 0 && (secs != 0 || usecs != 0))
44		ticks_delay = 1;
45	(void)taskDelay(ticks_delay);
46}
47