#include "BBC/FPA.h"
#include "BBC/LLI_protos.h"
#include "BBC/LLI.ih"
Data Structures | |
| struct | _FPA_fcb |
| Layouts the control structure for managing the list of free packets. This structure is private to the FPA utility. More... | |
| struct | _FPA_pcb |
| Layouts the control structure used by each packet on the free list This structure is private to the FPA utility. More... | |
Functions | |
| int | FPA_fcb_sizeof () |
| Returns the size of the Fixed Packet Allocator control block. More... | |
| int | FPA_pcb_sizeof () |
| Returns the size of the Packet control block. More... | |
| int | FPA_init (FPA_fcb *fcb, char *buffer, int buf_size, int packet_size, int pcb_offset, FPA_type type, FPA_cb_init init_routine, void *init_parameter) |
| Configures a user supplied piece of memory as a collection of fixed size packets which can be allocated and deallocated. More... | |
| int | FPA_destroy (FPA_fcb *fcb) |
| Releases any resources gathered at initialization time. More... | |
| void * | FPA_get (FPA_fcb *fcb) |
| Get or allocate a packet from the free list. More... | |
| void * | FPA_getW (FPA_fcb *fcb, int timeout) |
| Get or allocate a packet from the free list with a blocking. More... | |
| int | FPA_free (FPA_fcb *fcb, void *packet) |
| Returns a previously allocated packet to the free list. More... | |
The behaviour when the pool is exhausted is configurable to be either blocking or non-blocking. If blocking is choose, then the blocking can be in either FIFO or PRIORITY ordering.
A design choice was to hide both the control structure for the pool and the packet management structure. The former is an easy decision, the latter causes some awkward programming at times, but greatly increases modularity. The pain is almost exclusively limited to initialization. This is kind of an experiment to see if this works. If not, it will get changed.
USAGE/EXAMPLE
Here is how one would typically use this facility. Suppose one wished to manage a pool of packets which contained data which was to be read from an external source. Further suppose that each packet was to be have a fixed header describing the data type and that this type never changes.
FPA_fcb *fcb;
int pcb_size;
char *buffer[1000];
struct MyPacket { int data_type, char buf[46] };
fcb = malloc (FPA_fcb_sizeofb ()); / * Allocate the control block * /
FPA_init (fcb, / * FPA control block * /
buffer, / * Memory pool to manage * /
sizeof(buffer), / * Size of the memory pool * /
sizeof(struct MyPacket), / * Size of each packet * /
-1, / * Place PCB at the bottom * /
FPA_K_TYPE_FIFO_BLOCKING, / * Allow FIFO style blocking * /
(FPA_cb_init)initializer, / * Initialization routine * /
(void *)data_type); / * Data type of each packet * /
.
.
.
while (ptr = isDataReady ())
{
packet = FPA_getW (fcb, FPA_K_WTO_WAIT_FOREVER);
copy (ptr, packet, packet_size);
}
return;
}
/ * Callback routine to initialize each packet * /
void initializer (int data_type,
struct MyPacket *packet,
int packet_size,
int pcb_offset)
{
packet.data_type = data_type;
}
|
|
Releases any resources gathered at initialization time.
|
|
|
Returns the size of the Fixed Packet Allocator control block.
This call is for modularity reasons. The user can learn the size of memory needed by the FPA utility to manage a pool of packets without needing to know the details of how it is layed out. This could have also been achieved by having the FPA initialization routine allocate the control block, but this takes away the freedom of the user to control his own allocation and deallocation |
|
||||||||||||
|
Returns a previously allocated packet to the free list.
|
|
|
Get or allocate a packet from the free list.
|
|
||||||||||||
|
Get or allocate a packet from the free list with a blocking.
|
|
||||||||||||||||||||||||||||||||||||
|
Configures a user supplied piece of memory as a collection of fixed size packets which can be allocated and deallocated.
Various options allow the user to place where the control structure lives within the packet and determine the blocking style. The must usual choice for the placement of the packet control structure is at the beginning pcb_offset = 0, or at the end pcb_offset = -1, although the user is allowed to specify any offset, provided it is within the packet. The usual blocking style is FPA_K_TYPE_FIFO_BLOCKING.
|
|
|
Returns the size of the Packet control block.
|
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001