proginfo.doc

Just though some of you might have a use for info on rt's internal data
structures. For C programmers there's a headerfile included in this
distribution, here's the explanation of all fields:

First, we have the rt_MainList structure. This one can be found directly
following the public sempahore. Obtain a pointer to it like this:

struct SignalSemaphore *ss;
   ss = FindSemaphore(RT_SEMAPHORENAME);
   if(ss)
   {
   struct rt_MainList *ml;

      ObtainSemaphore(ss);
      ml = (struct rt_MainList*)(ss+1);

      /* your code here */
		ReleaseSemaphore(ss);
   }

The structure is not really complex :-)
struct rt_MainList
{
	struct MinList mlh;
	UWORD version;
};

The MinList structure is used to chain all resource types that are
currently being tracked. The version filed should be checked against
RT_VERSION to ensure the correct version of rt is running. Chained into the
MinList you'll find at least one MinNode structure. Directly following any
MinNode is a rt_ResList structure, so when you have a pointer to a node in
this list, find this node's rt_ResList with
reslist = (struct rt_ResList*)(currentnode+1);
Why didn't I put the MinNode definition inside the rt_ResList structure?
Well, it needed less casts in the first place so I kept it that way. You
can ofcourz change the rtPublic.h file to have a struct SignalSemaphore as
first element in the rt_MainList structure and a struct MinNode first in
the struct rt_ResList.


Next is:

struct rt_ResList
{
	struct MinList mlh;
	WORD allocoffset;
	WORD freeoffset;
	STRPTR libname;
	APTR pool;
	WORD idoffset;
	BYTE freereg;
	BYTE pad;
	ULONG totalloc;
	ULONG totfree;
};

This one is allocated once for every type of resource, that is: for every
valid line in the configfile. You'll recognize almost all fields from the
cfgfile template.
The MinList part is used to chain single resources by their rt_ResNode
structures. allocoffset/freeoffset/libname should be obvious. Note that the
offsets are in the corrected (negative) form already!
"pool" is a pointer to the memory pool used for allocation of the list
nodes, better don't touch this. "idoffset" is the offset of the description
string as explained in the main docfile; see rtPublic.h for a macro that
uses this field. "freereg" is again a parameter from the configfile,
specified as the plain register number for data registers and the number
plus 8 for address registers (the 68000 machinecode happens to use that
format for a couple of instructions :)). totalloc and totfree are counters
for the number of [de-]allocations that were made unter rt's control so
far. They can be used to quickly calculate the size of a resource list.

Finally:

struct rt_ResNode
{
	struct MinNode node;
	APTR resource;
	struct Task *task;
};

Structures like this (16 bytes in size as of V39.5 - don't rely on thissize
though!) are linked into the MinList contained in a struct rt_ResList.
Apart from their node they contain only a pointer to their ownertask (the
one that allocated the resource) and resource pointer. This one is typeless
(APTR) as it may be anything from an ASL-requester handle to BPTRs (for
filehandles or locks) to a screenpointer or something. The only thing you
can rely on is that [if everything went OK] the resoure will be freed if
you pass it to "freeoffset" in <libname> in the register <freereg>. If you
know the type of resource you are currently examining you may of course do
anything you like with it :-)

Have a look at the included file "FreeResource.a" to see how resources can
be killed!
