source: rtems-libbsd/rtemsbsd/src/rtems-bsd-timeout.c @ 459afb1

4.115-freebsd-12freebsd-9.3
Last change on this file since 459afb1 was 459afb1, checked in by Jennifer Averett <jennifer.averett@…>, on Apr 16, 2012 at 2:10:35 PM

Implemented a version of rmlock using rwlock.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief TODO.
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2012.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 * The license and distribution terms for this file may be
14 * found in the file LICENSE in this distribution or at
15 * http://www.rtems.com/license/LICENSE.
16 */
17
18#include <freebsd/machine/rtems-bsd-config.h>
19#include <freebsd/sys/cdefs.h>
20__FBSDID("$FreeBSD$");
21
22#include <freebsd/sys/param.h>
23#include <freebsd/sys/systm.h>
24#include <freebsd/sys/bus.h>
25#include <freebsd/sys/callout.h>
26#include <freebsd/sys/condvar.h>
27#include <freebsd/sys/interrupt.h>
28#include <freebsd/sys/kernel.h>
29#include <freebsd/sys/ktr.h>
30#include <freebsd/sys/lock.h>
31#include <freebsd/sys/malloc.h>
32#include <freebsd/sys/mutex.h>
33#include <freebsd/sys/proc.h>
34#include <freebsd/sys/sdt.h>
35
36static int timeout_cpu;
37/*
38 * There is one struct callout_cpu per cpu, holding all relevant
39 * state for the callout processing thread on the individual CPU.
40 * In particular:
41 *      cc_ticks is incremented once per tick in callout_cpu().
42 *      It tracks the global 'ticks' but in a way that the individual
43 *      threads should not worry about races in the order in which
44 *      hardclock() and hardclock_cpu() run on the various CPUs.
45 *      cc_softclock is advanced in callout_cpu() to point to the
46 *      first entry in cc_callwheel that may need handling. In turn,
47 *      a softclock() is scheduled so it can serve the various entries i
48 *      such that cc_softclock <= i <= cc_ticks .
49 *      XXX maybe cc_softclock and cc_ticks should be volatile ?
50 *
51 *      cc_ticks is also used in callout_reset_cpu() to determine
52 *      when the callout should be served.
53 */
54struct callout_cpu {
55        struct mtx              cc_lock;
56        struct callout          *cc_callout;
57        struct callout_tailq    *cc_callwheel;
58        struct callout_list     cc_callfree;
59        struct callout          *cc_next;
60        struct callout          *cc_curr;
61        void                    *cc_cookie;
62        int                     cc_ticks;
63        int                     cc_softticks;
64        int                     cc_cancel;
65        int                     cc_waiting;
66};
67
68/*
69 * timeout --
70 *      Execute a function after a specified length of time.
71 *
72 * untimeout --
73 *      Cancel previous timeout function call.
74 *
75 * callout_handle_init --
76 *      Initialize a handle so that using it with untimeout is benign.
77 *
78 *      See AT&T BCI Driver Reference Manual for specification.  This
79 *      implementation differs from that one in that although an
80 *      identification value is returned from timeout, the original
81 *      arguments to timeout as well as the identifier are used to
82 *      identify entries for untimeout.
83 */
84
85struct callout_handle
86timeout(ftn, arg, to_ticks)
87        timeout_t *ftn;
88        void *arg;
89        int to_ticks;
90{
91        struct callout_cpu *cc;
92        struct callout *new;
93        struct callout_handle handle;
94
95#if 0
96        cc = CC_CPU(timeout_cpu);
97        CC_LOCK(cc);
98        /* Fill in the next free callout structure. */
99        new = SLIST_FIRST(&cc->cc_callfree);
100        if (new == NULL)
101                /* XXX Attempt to malloc first */
102                panic("timeout table full");
103        SLIST_REMOVE_HEAD(&cc->cc_callfree, c_links.sle);
104        callout_reset(new, to_ticks, ftn, arg);
105        handle.callout = new;
106        CC_UNLOCK(cc);
107#endif
108        return (handle);
109}
110
111
Note: See TracBrowser for help on using the repository browser.