GGStoragePools.mesa
Contents: Routines for maintaining various storage pools and synchronizing their use. Synchronization is the main reason for the existence of this module. It provides a MONITOR lock for each storage pool.
Copyright Ó 1988, 1992 by Xerox Corporation. All rights reserved.
Bier, June 5, 1987 2:02:43 pm PDT
GGStoragePools: CEDAR DEFINITIONS =
BEGIN
MakeStorageProc: TYPE = PROC [pool: StoragePool];
AllocateProc: TYPE = PROC [pool: StoragePool] RETURNS [item: REF ANY];
FreeProc: TYPE = PROC [pool: StoragePool, item: REF ANY];
StoragePoolClass: TYPE = REF StoragePoolClassObj;
StoragePoolClassObj:
TYPE =
RECORD [
name: ATOM,
allocate: AllocateProc,
free: FreeProc
];
StoragePool: TYPE = REF StoragePoolObj;
StoragePoolObj:
TYPE =
MONITORED RECORD [
class: StoragePoolClass,
data: REF ANY
];
CreateClass:
PROC [name:
ATOM, allocate: AllocateProc, free: FreeProc]
RETURNS [class: StoragePoolClass];
allocate is called by Allocate. It returns one REF from the pool to the caller. allocate is also a good place to initialize fields in the REF. free is called by Free. It allows the caller to return one REF to the pool, when the caller is done with it.
CreatePool:
PROC [class: StoragePoolClass, makeStorage: MakeStorageProc]
RETURNS [pool: StoragePool];
Creates a new pool and allows makeStorage to allocate some number of REFs to serve as the pool contents.
Allocate:
PROC [pool: StoragePool]
RETURNS [item:
REF
ANY];
calls pool.allocate.
Free:
PROC [pool: StoragePool, item:
REF
ANY];
calls pool.free.
END.