openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

resource.h (1895B)


      1 /* Copyright 1998-1999, Brian J. Swetland. All rights reserved.
      2 ** Distributed under the terms of the OpenBLT License
      3 */
      4 
      5 #ifndef _RESOURCE_H_
      6 #define _RESOURCE_H_
      7 
      8 #include "types.h"
      9 #include "list.h"
     10 
     11 typedef enum 
     12 {
     13     RSRC_NONE, RSRC_TASK, RSRC_ASPACE, RSRC_PORT, RSRC_SEM, RSRC_RIGHT,
     14     RSRC_AREA, RSRC_QUEUE, RSRC_TEAM, RSRC_MAX
     15 } rsrc_type;
     16 
     17 struct __resource_t
     18 {
     19 	uint32 id;    
     20 	rsrc_type type;
     21 	team_t *owner;
     22 	
     23 	list_t rights;
     24 	list_t queue;
     25 	
     26 	char name[32];
     27 };
     28 
     29 
     30 /* initialize the resource map */
     31 void rsrc_init(void *map, int size);
     32 
     33 /* locate a specifically typed resource */
     34 void *rsrc_find(int type, int id);
     35 
     36 /* remove the resource from the table */
     37 void rsrc_release(resource_t *r);
     38 
     39 /* assign a portnumber and put it in the resource table */
     40 void rsrc_bind(resource_t *r, rsrc_type type, team_t *owner);
     41 
     42 void rsrc_set_owner(resource_t *r, team_t *owner);
     43 void rsrc_set_name(resource_t *r, const char *name);
     44 
     45 /* usercall - return the rsrc_id of the owner of the resource */
     46 int rsrc_identify(uint32 id);
     47 
     48 void rsrc_enqueue(resource_t *rsrc, task_t *task);
     49 void rsrc_enqueue_ordered(resource_t *rsrc, task_t *task, uint32 wake_time);
     50 task_t *rsrc_dequeue(resource_t *rsrc);
     51 const char *rsrc_typename(resource_t *rsrc);
     52 
     53 task_t *rsrc_queue_peek(resource_t *rsrc);
     54 
     55 #define rsrc_find_task(id)   ((task_t *) rsrc_find(RSRC_TASK,   id))
     56 #define rsrc_find_port(id)   ((port_t *) rsrc_find(RSRC_PORT,   id))
     57 #define rsrc_find_aspace(id) ((aspace_t *) rsrc_find(RSRC_ASPACE, id))
     58 #define rsrc_find_sem(id)    ((sem_t *) rsrc_find(RSRC_SEM, id))
     59 #define rsrc_find_area(id)   ((area_t *) rsrc_find(RSRC_AREA, id))
     60 #define rsrc_find_right(id)  ((right_t *) rsrc_find(RSRC_RIGHT, id))
     61 #define rsrc_find_queue(id)  ((resource_t *) rsrc_find(RSRC_QUEUE, id))
     62 #define rsrc_find_team(id)   ((team_t *) rsrc_find(RSRC_TEAM, id))
     63 
     64 int queue_create(const char *name, team_t *team);
     65 
     66 #endif