source: rtems-libbsd/rtemsbsd/src/rtems-bsd-timeout.c @ 8420b94

4.115-freebsd-12freebsd-9.3
Last change on this file since 8420b94 was 8420b94, checked in by Jennifer Averett <jennifer.averett@…>, on May 8, 2012 at 2:14:42 PM

Modified copyright on rtems-bsd-xxx files to be consistant with FreeBSD copyright.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief TODO.
7 */
8
9/*
10 * COPYRIGHT (c) 2012.
11 * On-Line Applications Research Corporation (OAR).
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#include <freebsd/machine/rtems-bsd-config.h>
37#include <freebsd/sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40#include <freebsd/sys/param.h>
41#include <freebsd/sys/systm.h>
42#include <freebsd/sys/bus.h>
43#include <freebsd/sys/callout.h>
44#include <freebsd/sys/condvar.h>
45#include <freebsd/sys/interrupt.h>
46#include <freebsd/sys/kernel.h>
47#include <freebsd/sys/ktr.h>
48#include <freebsd/sys/lock.h>
49#include <freebsd/sys/malloc.h>
50#include <freebsd/sys/mutex.h>
51#include <freebsd/sys/proc.h>
52#include <freebsd/sys/sdt.h>
53
54static int timeout_cpu;
55/*
56 * There is one struct callout_cpu per cpu, holding all relevant
57 * state for the callout processing thread on the individual CPU.
58 * In particular:
59 *      cc_ticks is incremented once per tick in callout_cpu().
60 *      It tracks the global 'ticks' but in a way that the individual
61 *      threads should not worry about races in the order in which
62 *      hardclock() and hardclock_cpu() run on the various CPUs.
63 *      cc_softclock is advanced in callout_cpu() to point to the
64 *      first entry in cc_callwheel that may need handling. In turn,
65 *      a softclock() is scheduled so it can serve the various entries i
66 *      such that cc_softclock <= i <= cc_ticks .
67 *      XXX maybe cc_softclock and cc_ticks should be volatile ?
68 *
69 *      cc_ticks is also used in callout_reset_cpu() to determine
70 *      when the callout should be served.
71 */
72struct callout_cpu {
73        struct mtx              cc_lock;
74        struct callout          *cc_callout;
75        struct callout_tailq    *cc_callwheel;
76        struct callout_list     cc_callfree;
77        struct callout          *cc_next;
78        struct callout          *cc_curr;
79        void                    *cc_cookie;
80        int                     cc_ticks;
81        int                     cc_softticks;
82        int                     cc_cancel;
83        int                     cc_waiting;
84};
85
86/*
87 * timeout --
88 *      Execute a function after a specified length of time.
89 *
90 * untimeout --
91 *      Cancel previous timeout function call.
92 *
93 * callout_handle_init --
94 *      Initialize a handle so that using it with untimeout is benign.
95 *
96 *      See AT&T BCI Driver Reference Manual for specification.  This
97 *      implementation differs from that one in that although an
98 *      identification value is returned from timeout, the original
99 *      arguments to timeout as well as the identifier are used to
100 *      identify entries for untimeout.
101 */
102
103struct callout_handle
104timeout(ftn, arg, to_ticks)
105        timeout_t *ftn;
106        void *arg;
107        int to_ticks;
108{
109        struct callout_cpu *cc;
110        struct callout *new;
111        struct callout_handle handle;
112
113#if 0
114        cc = CC_CPU(timeout_cpu);
115        CC_LOCK(cc);
116        /* Fill in the next free callout structure. */
117        new = SLIST_FIRST(&cc->cc_callfree);
118        if (new == NULL)
119                /* XXX Attempt to malloc first */
120                panic("timeout table full");
121        SLIST_REMOVE_HEAD(&cc->cc_callfree, c_links.sle);
122        callout_reset(new, to_ticks, ftn, arg);
123        handle.callout = new;
124        CC_UNLOCK(cc);
125#endif
126        return (handle);
127}
128
129
Note: See TracBrowser for help on using the repository browser.