mirror of https://github.com/zrafa/xinu-avr.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
995 B
39 lines
995 B
/* freebuf.c - freebuf */ |
|
|
|
#include <xinu.h> |
|
|
|
/*------------------------------------------------------------------------ |
|
* freebuf - Free a buffer that was allocated from a pool by getbuf |
|
*------------------------------------------------------------------------ |
|
*/ |
|
syscall freebuf( |
|
char *bufaddr /* Address of buffer to return */ |
|
) |
|
{ |
|
intmask mask; /* Saved interrupt mask */ |
|
struct bpentry *bpptr; /* Pointer to entry in buftab */ |
|
bpid32 poolid; /* ID of buffer's pool */ |
|
|
|
mask = disable(); |
|
|
|
/* Extract pool ID from integer prior to buffer address */ |
|
|
|
bufaddr -= sizeof(bpid32); |
|
poolid = *(bpid32 *)bufaddr; |
|
if (poolid < 0 || poolid >= nbpools) { |
|
restore(mask); |
|
return SYSERR; |
|
} |
|
|
|
/* Get address of correct pool entry in table */ |
|
|
|
bpptr = &buftab[poolid]; |
|
|
|
/* Insert buffer into list and signal semaphore */ |
|
|
|
((struct bpentry *)bufaddr)->bpnext = bpptr->bpnext; |
|
bpptr->bpnext = (struct bpentry *)bufaddr; |
|
signal(bpptr->bpsem); |
|
restore(mask); |
|
return OK; |
|
}
|
|
|