/* Two handy macros for handling ResourceLists and MinLists
** (slightly changed list macros from exec/lists.h)
*/
#define IsResrcListEmpty(x) \
	( ((x)->mlh.mlh_TailPred) == (struct MinNode *)(x) )
#define IsMinListEmpty(x) \
	( ((x)->mlh_TailPred) == (struct MinNode *)(x) )

/* a macro to quickly get the number of allocations from a resource list */
#define CURRENTALLOCS(list) (list->totalloc - list->totfree)

/* makes a stringpointer to resource description from pointer to resource node */
#define RESOURCE_IDSTRING(rn) (*((STRPTR*)((UBYTE*)(rn->resource)+rl->idoffset)))

/* name of the public semaphore created by rt */
#define RT_SEMAPHORENAME "ResourceTracker"

/* Version and revision numbers to check
** These are not identical with the program versions! They are only changed
** when the format of rt's data structures changes.
*/
#define RT_STRUCTVERSION 39
#define RT_STRUCTREVISION 5
#define RT_VERSION ((RT_STRUCTVERSION<<8) | RT_STRUCTREVISION)

/* the node structure for a single resource */
struct rt_ResNode
{
	struct MinNode node;
	APTR resource;
	struct Task *task;
};

/* the main list, to be found directly following the public sempahore */
struct rt_MainList
{
	struct MinList mlh;
	UWORD version;
};

/* the list structure for a single resource type. allocated once for every
** alloc()/free() pair
*/
struct rt_ResList
{
	struct MinList mlh;
	WORD allocoffset;
	WORD freeoffset;
	STRPTR libname;
	APTR pool;
	WORD idoffset;
	BYTE freereg;
	BYTE pad;
	ULONG totalloc;
	ULONG totfree;
};

/* the prototype for the FreeResource() asm function */
extern __far __asm FreeResource(register __a3 APTR resource, register __a4 struct rt_ResList*);
