4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
30 * All Rights Reserved.
37 * \author Bernie Innocenti <bernie@codewiz.org>
38 * \author Stefano Fedrigo <aleph@develer.com>
41 #ifndef MWARE_RESOURCE_H
42 #define MWARE_RESOURCE_H
44 #include <drv/timer.h> // time_t
47 #warning FIXME:Revise me!
50 * Abstract locking primitives used by host OS.
52 typedef Semaphore ResourceLock;
53 #define ResMan_sleep() timer_delay(1)
54 #define ResMan_time_t mtime_t
62 * Hold context information for a resource such as an audio channel.
64 * Each driver registers one or more Resource instances with the
65 * ResMan using ResMan_Register().
67 * Clients can then allocate the resource through ResMan_Alloc()
68 * providing a desired priority and an Observer for asynchronous
71 * Allocated resources can be stolen by other clients asking for a
72 * higher priority. ResMan notifies a preemption request by invoking
73 * the Observer of the current owner.
75 * The Observer callback must take whatever action is needed to
76 * release the resource as soon as possible to avoid blocking the
79 typedef struct Resource
82 /// Control access to fields below.
85 /// Pointer to current owner's observer. NULL if resource is free.
86 struct Observer *owner;
88 /// Priority of current owner (higher values mean higher priority).
91 /// Queue of processes waiting to obtain the resource.
95 /// Event sent by ResMan to owners when to request resource release.
96 enum { EVENT_RELEASE = 1 };
98 /// Try to allocate a resource \a res with priority \a pri for at most \a timeout ticks.
99 bool ResMan_Alloc(Resource *res, int pri, ResMan_time_t timeout, struct Observer *releaseRequest);
101 /// Free resource \a res. Will eventually wake-up other queued owners.
102 void ResMan_Free(Resource *res);
104 void ResMan_Init(Resource *res);
106 #endif /* MWARE_RESOURCE_H */