root.c File Reference

Root Sets. More...

#include "internal.h"
Include dependency graph for root.c:

Go to the source code of this file.

Defines

#define MAX_ROOTS   (sizeof(tm.roots)/sizeof(tm.roots[0]))

Functions

static int _tm_root_add_1 (tm_root *a)
 Add a single root set.
static int tm_root_subtract (tm_root *a, tm_root *b, tm_root *c)
 Subtract b from a, returning result in c.
static void _tm_root_add (tm_root *a)
 Add a root set, while splitting it by anti-roots.
int tm_root_add (const char *name, const void *l, const void *h)
 API: Add a root set.
void tm_root_remove (const char *name, const void *l, const void *h)
int tm_ptr_is_in_root_set (const void *ptr)

Detailed Description

Root Sets.

Definition in file root.c.


Define Documentation

#define MAX_ROOTS   (sizeof(tm.roots)/sizeof(tm.roots[0]))

Referenced by _tm_root_add_1().


Function Documentation

static void _tm_root_add ( tm_root a  )  [static]

Add a root set, while splitting it by anti-roots.

Definition at line 172 of file root.c.

References _tm_root_add_1(), tm_data::aroots, tm_data::naroots, tm, and tm_root_subtract().

Referenced by tm_root_add(), and tm_root_remove().

00173 {
00174   int i;
00175   tm_root c[2];
00176 
00177   /* Scan anti-roots for possible splitting */
00178   for ( i = 0; i < tm.naroots; ++ i ) {
00179     switch ( tm_root_subtract(a, &tm.aroots[i], c) ) {
00180     case -1: /* deleted */
00181       return;
00182       break;
00183       
00184     case 0: /* OK */
00185       break;
00186       
00187     case 1: /* clipped */
00188       *a = c[0];
00189       break;
00190       
00191     case 2: /* split */
00192       _tm_root_add(&c[0]);
00193       *a = c[1];
00194       break;
00195     }
00196   }
00197 
00198   _tm_root_add_1(a);
00199 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int _tm_root_add_1 ( tm_root a  )  [static]

Add a single root set.

Definition at line 12 of file root.c.

References tm_root::h, tm_root::l, MAX_ROOTS, tm_root::name, tm_data::nroots, tm_data::root_datai, tm_data::root_newi, tm_data::roots, tm, tm_assert_test, and tm_msg().

Referenced by _tm_root_add().

00013 {
00014   int i;
00015 #define MAX_ROOTS (sizeof(tm.roots)/sizeof(tm.roots[0]))
00016 
00017   if ( a->l >= a->h )
00018     return -1;
00019 
00020   /* Scan for empty slot. */
00021   for ( i = 0; i < MAX_ROOTS; ++ i ) {
00022     if ( tm.roots[i].name == 0 || tm.roots[i].l == tm.roots[i].h ) {
00023       break;
00024     }
00025   }
00026 
00027   if ( tm.nroots <= i ) {
00028     tm.nroots = i + 1;
00029   }
00030 
00031   tm_assert_test(i < MAX_ROOTS);
00032   tm_assert_test(i >= tm.root_datai);
00033 
00034   if ( tm.root_newi == -1 ) {
00035     tm.root_newi = i;
00036   }
00037 
00038   tm.roots[i] = *a;
00039 
00040   tm_msg("R a [%p,%p] %s %d\n", 
00041          tm.roots[i].l, 
00042          tm.roots[i].h,
00043          tm.roots[i].name,
00044          i);
00045 
00046   return i;
00047 }

Here is the call graph for this function:

Here is the caller graph for this function:

int tm_ptr_is_in_root_set ( const void *  ptr  ) 

Definition at line 274 of file root.c.

References tm_root::h, tm_root::l, tm_data::nroots, tm_data::roots, and tm.

Referenced by tm_init().

00275 {
00276   int i;
00277 
00278   for ( i = 0; i < tm.nroots; ++ i ) {
00279     if ( tm.roots[i].l <= ptr && ptr < tm.roots[i].h ) {
00280       return i + 1;
00281     }
00282   }
00283 
00284   return 0;
00285 }

Here is the caller graph for this function:

static int tm_root_subtract ( tm_root a,
tm_root b,
tm_root c 
) [static]

Subtract b from a, returning result in c.

Return 0 if b is empty.

Case: b in a:

 a   L-------------------------------------------H
 b      L--------------------H
 c   0
 

Return -1.

Case: b out of a:

 a   L-------------H                        L--------------H
 b                   L--------------------H
 c   0
 

Return 0.

Case: b is in a:

 a            L------H
 b   H-----------------------H
 c1                  L-------H
 c2  L--------H
 

Save c1 and c2. Return 2.

Case: b.h in a:

 a          L---------------------H
 b    L--------------------H
 c                         L------H
 

Return 1.

Case: b.l in a:

 a   L---------------------H
 b             L--------------------H
 c   L---------H
 

Return 1.

Definition at line 56 of file root.c.

References tm_root::h, tm_root::l, and tm_abort().

Referenced by _tm_root_add(), and tm_root_remove().

00057 {
00058   const void *tmp;
00059 
00060   if ( a->l > a->h ) {
00061     tmp = a->l; a->l = a->h; a->h = tmp;
00062   }
00063   if ( b->l > b->h ) {
00064     tmp = b->l; b->l = b->h; b->h = tmp;
00065   }
00066   /*! Return 0 if b is empty. */
00067   if ( b->l == b->h ) {
00068     return 0;
00069   }
00070 
00071   if ( (a->l == b->l) || (b->l <= a->l && a->h <= b->h) ) {
00072     /**
00073      * Case: b in a:
00074      *
00075      * <pre>
00076      *
00077      * a   L-------------------------------------------H
00078      * b      L--------------------H
00079      * c   0
00080      *
00081      * </pre>
00082      *
00083      * Return -1.
00084      */
00085     return -1; /* Delete flag */
00086   }
00087   if ( b->h <= a->l || b->l >= a->h ) {
00088     /**
00089      * Case: b out of a:
00090      *
00091      * <pre>
00092      *
00093      * a   L-------------H                        L--------------H
00094      * b                   L--------------------H
00095      * c   0
00096      *
00097      * </pre>
00098      *
00099      * Return 0.
00100      */
00101     /* *c = *a; */
00102     return 0;
00103   }
00104   if ( a->l < b->l && b->h < a->h ) {
00105     /**
00106      * Case: b is in a:
00107      *
00108      * <pre>
00109      *
00110      * a            L------H
00111      * b   H-----------------------H
00112      * c1                  L-------H
00113      * c2  L--------H
00114      *
00115      * </pre>
00116      *
00117      * Save c1 and c2.
00118      * Return 2.
00119      */
00120     c[0] = *a;
00121     c[0].l = b->h;
00122     c[1] = *a;
00123     c[1].h = b->l;
00124     return 2;
00125   }
00126   if ( a->l < b->h && b->h <= a->h ) {
00127     /**
00128      * Case: b.h in a:
00129      *
00130      * <pre>
00131      *
00132      * a          L---------------------H
00133      * b    L--------------------H
00134      * c                         L------H
00135      *
00136      * </pre>
00137      *
00138      * Return 1.
00139      */
00140     *c = *a;
00141     c->l = b->h;
00142     return 1;
00143   }
00144   if ( a->l < b->l && b->l <= a->h ) {
00145     /**
00146      * Case: b.l in a:
00147      *
00148      * <pre>
00149      *
00150      * a   L---------------------H
00151      * b             L--------------------H
00152      * c   L---------H
00153      *
00154      * </pre>
00155      *
00156      * Return 1.
00157      */
00158     *c = *a;
00159     c->h = b->l;
00160     return 1;
00161   }
00162 
00163   tm_abort();
00164   return -1;
00165 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Mon Jan 25 06:33:12 2010 for TM(tredmill) by  doxygen 1.6.1