X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=mware%2Fresource.h;h=15736a753f11e72776a05093afd83abd58638a66;hb=HEAD;hp=f30b232f8edfddc7522c217d8b46f462bde7e261;hpb=564dbedb34c9f1422f59385071496af51ddc5910;p=bertos.git diff --git a/mware/resource.h b/mware/resource.h deleted file mode 100755 index f30b232f..00000000 --- a/mware/resource.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef MWARE_RESOURCE_H -#define MWARE_RESOURCE_H - -#include // time_t -#include - -/* - * Abstract locking primitives used by host OS. - */ -#if CONFIG_KERNEL - - typedef Semaphore ResourceLock; - #define ResMan_sleep() timer_delay(1) - #define ResMan_time_t mtime_t - -#else /* FreeRTOS */ - - #include - #include - #include // vTaskDelay() - - #define ResMan_sleep() vTaskDelay((portTickType)1 * portTICK_RATE_MS) - #define ResMan_time_t portTickType -#endif - - -// Forward decl -struct Observer; - -/** - * Hold context information for a resource such as an audio channel. - * - * Each driver registers one or more Resource instances with the - * ResMan using ResMan_Register(). - * - * Clients can then allocate the resource through ResMan_Alloc() - * providing a desired priority and an Observer for asynchronous - * notification. - * - * Allocated resources can be stolen by other clients asking for a - * higher priority. ResMan notifies a preemption request by invoking - * the Observer of the current owner. - * - * The Observer callback must take whatever action is needed to - * release the resource as soon as possible to avoid blocking the - * new owner. - */ -typedef struct Resource -{ -//Private - /// Control access to fields below. - Semaphore lock; - - /// Pointer to current owner's observer. NULL if resource is free. - struct Observer *owner; - - /// Priority of current owner (higher values mean higher priority). - int pri; - - /// Queue of processes waiting to obtain the resource. - List queue; -} Resource; - -/// Event sent by ResMan to owners when to request resource release. -enum { EVENT_RELEASE = 1 }; - -/// Try to allocate a resource \a res with priority \a pri for at most \a timeout ticks. -bool ResMan_Alloc(Resource *res, int pri, ResMan_time_t timeout, struct Observer *releaseRequest); - -/// Free resource \a res. Will eventually wake-up other queued owners. -void ResMan_Free(Resource *res); - -void ResMan_Init(Resource *res); - -#endif /* MWARE_RESOURCE_H */