1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
/*
* Copyright (c) 1996, 1998, 1999 University of Utah and the Flux Group.
* All rights reserved.
*
* This file is part of the Flux OSKit. The OSKit is free software, also known
* as "open source;" you can redistribute it and/or modify it under the terms
* of the GNU General Public License (GPL), version 2, as published by the Free
* Software Foundation (FSF). To explore alternate licensing terms, contact
* the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
*
* The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
* received a copy of the GPL along with the OSKit; see the file COPYING. If
* not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
*/
/*
* Sleep/wakeup object. This implementation does very little!
*/
#include <oskit/debug.h>
#include <oskit/com.h>
#include <oskit/com/services.h>
#include <oskit/dev/dev.h>
#include <oskit/dev/osenv_sleep.h>
#include <stdlib.h>
#include <malloc.h>
/* COM object for oskit_osenv_sleep */
static struct oskit_osenv_sleep_ops my_sleep_ops;
#ifdef CPUNITS
struct oskit_osenv_sleep my_sleep_object = { &my_sleep_ops };
#else
static struct oskit_osenv_sleep my_sleep_object = { &my_sleep_ops };
#endif
/***************************************************************************
*
* Older osenv sleep interface. This includes a factory to create a
* new-style sleep object (see below).
*/
static OSKIT_COMDECL
simple_sleep_query(oskit_osenv_sleep_t *b,
const struct oskit_guid *iid, void **out_ihandle)
{
if (memcmp(iid, &oskit_iunknown_iid, sizeof(*iid)) == 0 ||
memcmp(iid, &oskit_osenv_sleep_iid, sizeof(*iid)) == 0) {
*out_ihandle = b;
return 0;
}
*out_ihandle = NULL;
return OSKIT_E_NOINTERFACE;
}
static OSKIT_COMDECL_U
simple_sleep_addref(oskit_osenv_sleep_t *b)
{
return 1;
}
static OSKIT_COMDECL_U
simple_sleep_release(oskit_osenv_sleep_t *b)
{
return 1;
}
static OSKIT_COMDECL_V
simple_sleep_init(oskit_osenv_sleep_t *o, osenv_sleeprec_t *sr)
{
osenv_sleep_init(sr);
}
static OSKIT_COMDECL_U
simple_sleep_sleep(oskit_osenv_sleep_t *o, osenv_sleeprec_t *sr)
{
return osenv_sleep(sr);
}
static OSKIT_COMDECL_V
simple_sleep_wakeup(oskit_osenv_sleep_t *o,
osenv_sleeprec_t *sr, int wakeup_status)
{
osenv_wakeup(sr, wakeup_status);
}
/*
* function to create a sleep object.
*/
static OSKIT_COMDECL
simple_sleep_create(oskit_osenv_sleep_t *b, oskit_sleep_t **out_sleep)
{
static oskit_error_t sleep_object_create(oskit_sleep_t **);
return sleep_object_create(out_sleep);
}
static struct oskit_osenv_sleep_ops my_sleep_ops = {
simple_sleep_query,
simple_sleep_addref,
simple_sleep_release,
simple_sleep_init,
simple_sleep_sleep,
simple_sleep_wakeup,
simple_sleep_create,
};
#ifndef CPUNITS
/*
* Return a reference to the "default" sleep object factory.
*
* In this implementation, the oskit_osenv_intr_t parameter is ignored.
* in favor of direct calls into other parts of the device library. A
* different implementation is free to do something more complicated.
*/
oskit_osenv_sleep_t *
oskit_create_osenv_sleep(oskit_osenv_intr_t *iface)
{
return &my_sleep_object;
}
#endif
/***************************************************************************
*
* New sleep object interface. Will eventually replace above interface.
*/
/* Ops for new sleep object */
static struct oskit_sleep_ops sleep_ops;
struct sleeper {
oskit_sleep_t sleepi; /* Sleep COM interface */
oskit_u32_t count; /* Reference count */
osenv_sleeprec_t sleeprec; /* Sleep record */
};
static OSKIT_COMDECL
sleep_query(oskit_sleep_t *s, const oskit_iid_t *iid, void **out_ihandle)
{
struct sleeper *sleeper = (struct sleeper *) s;
if (memcmp(iid, &oskit_iunknown_iid, sizeof(*iid)) == 0 ||
memcmp(iid, &oskit_sleep_iid, sizeof(*iid)) == 0) {
*out_ihandle = s;
sleeper->count++;
return 0;
}
*out_ihandle = 0;
return OSKIT_E_NOINTERFACE;
};
static OSKIT_COMDECL_U
sleep_addref(oskit_sleep_t *s)
{
/* I can't imagine it makes any sense to share a sleep object! */
osenv_panic(__FILE__":sleep_addref: "
"Adding a reference to a sleep object? %p", s);
return 0;
}
static OSKIT_COMDECL_U
sleep_release(oskit_sleep_t *s)
{
struct sleeper *sleeper = (struct sleeper *) s;
int newcount;
osenv_assert(sleeper->count);
if ((newcount = --sleeper->count) == 0) {
sfree(sleeper, sizeof(oskit_sleep_t));
return 0;
}
return newcount;
}
static OSKIT_COMDECL_U
sleep_sleep(oskit_sleep_t *s)
{
struct sleeper *sleeper = (struct sleeper *) s;
oskit_u32_t status;
status = osenv_sleep(&sleeper->sleeprec);
/*
* The sleep object might be reused, so reinitialize it for
* next time.
*/
osenv_sleep_init(&sleeper->sleeprec);
return status;
}
static OSKIT_COMDECL_U
sleep_sleep_consume(oskit_sleep_t *s)
{
struct sleeper *sleeper = (struct sleeper *) s;
oskit_u32_t status;
status = osenv_sleep(&sleeper->sleeprec);
/*
* The sleep object is used once and released.
*/
if (sleep_release(s))
osenv_panic(__FILE__":sleep_consume: non-zero reference count");
return status;
}
static OSKIT_COMDECL_V
sleep_wakeup(oskit_sleep_t *s, oskit_u32_t status)
{
struct sleeper *sleeper = (struct sleeper *) s;
osenv_wakeup(&sleeper->sleeprec, status);
}
/*
* Internal function to create a sleep object.
*/
static oskit_error_t
sleep_object_create(oskit_sleep_t **out_sleep)
{
struct sleeper *sleeper;
if ((sleeper = (struct sleeper *) malloc(sizeof(*sleeper))) == NULL)
return OSKIT_ENOMEM;
sleeper->count = 1;
sleeper->sleepi.ops = &sleep_ops;
osenv_sleep_init(&sleeper->sleeprec);
*out_sleep = &sleeper->sleepi;
return 0;
}
static struct oskit_sleep_ops sleep_ops = {
sleep_query,
sleep_addref,
sleep_release,
sleep_sleep,
sleep_sleep_consume,
sleep_wakeup,
};
|