Next | Prev | Up | Top | Contents | Index

Suballocation Functions

The functions summarized in Table 9-6 are used to manage suballocation of any resource.

Functions for Suballocation
Function NameHeader FilesCan Sleep?Purpose
rmalloc(D3) map.h & types.hNAllocate space from a private space management map.
rmalloc_wait(D3) map.h & types.hYAllocate resources from a space management map.
rmallocmap(D3) map.h & types.hNAllocate and initialize a private space management map.
rmfree(D3) map.h & types.hNRelease resources into a space management map.
rmfreemap(D3) map.h & types.hNFree a private space management map.

You use these functions as a convenient, efficient set of subroutines for allocating some resource--for example, disk sectors--that you obtain by other means. The expected sequence of use is as follows.

  1. During driver initialization, or possibly in pfxopen(), use rmallocmap() to allocate a map. A map is a data structure large enough to keep track of as many objects as you will create. Initially the map reflects no available resources.

  2. Use rmfree() to release existing resources into the map. For example, while opening a disk drive, you could use rmfree() to release all unused sectors into a sector map.

  3. When a resource is needed in an upper-half routine, use rmalloc() or rmalloc_wait() to acquire it. The index number of the first allocated item is returned.

  4. When a resource is released in any entry point, use rmfree() to note the available items and to wake up any upper-half process waiting in rmalloc_wait().

  5. On device close or when the driver is unloaded, use rmfreemap() to release the map itself.

Next | Prev | Up | Top | Contents | Index