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