Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (21 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28dir.info
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libobjc/sarray.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    11/* Sparse Arrays for Objective C dispatch tables
    2    Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
     2   Copyright (C) 1993, 1995, 1996, 2002 Free Software Foundation, Inc.
    33
    44This file is part of GNU CC.
     
    3535int idxsize = 0;                                        /* !T:MUTEX */
    3636
    37 static void *   first_free_data = NULL;                 /* !T:MUTEX */
     37static void *first_free_data = NULL;                    /* !T:MUTEX */
    3838
    3939#ifdef OBJC_SPARSE2
    40 const char* __objc_sparse2_id = "2 level sparse indices";
    41 #endif
    42 
    43 #ifdef OBJC_SPARSE3
    44 const char* __objc_sparse3_id = "3 level sparse indices";
     40const char *__objc_sparse2_id = "2 level sparse indices";
     41#endif
     42
     43#ifdef OBJC_SPARSE3
     44const char *__objc_sparse3_id = "3 level sparse indices";
    4545#endif
    4646
     
    4848   that were not safe in a multi-threaded environment. */
    4949void
    50 sarray_remove_garbage(void)
     50sarray_remove_garbage (void)
    5151{
    5252  void **vp;
    5353  void *np;
    5454 
    55   objc_mutex_lock(__objc_runtime_mutex);
     55  objc_mutex_lock (__objc_runtime_mutex);
    5656
    5757  vp = first_free_data;
     
    6060  while (vp) {
    6161    np = *vp;
    62     objc_free(vp);
     62    objc_free (vp);
    6363    vp = np;
    6464  }
    6565 
    66   objc_mutex_unlock(__objc_runtime_mutex);
     66  objc_mutex_unlock (__objc_runtime_mutex);
    6767}
    6868
     
    7272
    7373static void
    74 sarray_free_garbage(void *vp)
    75 {
    76   objc_mutex_lock(__objc_runtime_mutex);
     74sarray_free_garbage (void *vp)
     75{
     76  objc_mutex_lock (__objc_runtime_mutex);
    7777 
    7878  if (__objc_runtime_threads_alive == 1) {
    79     objc_free(vp);
     79    objc_free (vp);
    8080    if (first_free_data)
    81       sarray_remove_garbage();
     81      sarray_remove_garbage ();
    8282  }
    8383  else {
     
    8686  }
    8787     
    88   objc_mutex_unlock(__objc_runtime_mutex);
     88  objc_mutex_unlock (__objc_runtime_mutex);
    8989}
    9090
    9191/* sarray_at_put : copies data in such a way as to be thread reader safe. */
    9292void
    93 sarray_at_put(struct sarray* array, sidx index, void* element)
    94 {
    95 #ifdef OBJC_SPARSE3
    96   struct sindex** the_index;
    97   struct sindexnew_index;
    98 #endif
    99   struct sbucket** the_bucket;
    100   struct sbucketnew_bucket;
     93sarray_at_put (struct sarray *array, sidx index, void *element)
     94{
     95#ifdef OBJC_SPARSE3
     96  struct sindex **the_index;
     97  struct sindex *new_index;
     98#endif
     99  struct sbucket **the_bucket;
     100  struct sbucket *new_bucket;
    101101#ifdef OBJC_SPARSE3
    102102  size_t ioffset;
     
    123123#endif /* not PRECOMPUTE_SELECTORS */
    124124
    125   assert(soffset_decode(index) < array->capacity); /* Range check */
     125  assert (soffset_decode (index) < array->capacity); /* Range check */
    126126
    127127#ifdef OBJC_SPARSE3
     
    142142
    143143    /* The index was previously empty, allocate a new */
    144     new_index = (struct sindex*)objc_malloc(sizeof(struct sindex));
    145     memcpy(new_index, array->empty_index, sizeof(struct sindex));
     144    new_index = (struct sindex *) objc_malloc (sizeof (struct sindex));
     145    memcpy (new_index, array->empty_index, sizeof (struct sindex));
    146146    new_index->version.version = array->version.version;
    147147    *the_index = new_index;                     /* Prepared for install. */
     
    152152
    153153    /* This index must be lazy copied */
    154     struct sindex* old_index = *the_index;
    155     new_index = (struct sindex*)objc_malloc(sizeof(struct sindex));
    156     memcpy( new_index, old_index, sizeof(struct sindex));
     154    struct sindex *old_index = *the_index;
     155    new_index = (struct sindex *) objc_malloc (sizeof (struct sindex));
     156    memcpy (new_index, old_index, sizeof (struct sindex));
    157157    new_index->version.version = array->version.version;
    158158    *the_index = new_index;                     /* Prepared for install. */
     
    170170    /* The bucket was previously empty (or something like that), */
    171171    /* allocate a new.  This is the effect of `lazy' allocation */ 
    172     new_bucket = (struct sbucket*)objc_malloc(sizeof(struct sbucket));
    173     memcpy((void *) new_bucket, (const void*)array->empty_bucket,
    174            sizeof(struct sbucket));
     172    new_bucket = (struct sbucket *) objc_malloc (sizeof (struct sbucket));
     173    memcpy ((void *) new_bucket, (const void *) array->empty_bucket,
     174            sizeof (struct sbucket));
    175175    new_bucket->version.version = array->version.version;
    176176    *the_bucket = new_bucket;                   /* Prepared for install. */
     
    181181
    182182    /* Perform lazy copy. */
    183     struct sbucket* old_bucket = *the_bucket;
    184     new_bucket = (struct sbucket*)objc_malloc(sizeof(struct sbucket));
    185     memcpy( new_bucket, old_bucket, sizeof(struct sbucket));
     183    struct sbucket *old_bucket = *the_bucket;
     184    new_bucket = (struct sbucket *) objc_malloc (sizeof (struct sbucket));
     185    memcpy (new_bucket, old_bucket, sizeof (struct sbucket));
    186186    new_bucket->version.version = array->version.version;
    187187    *the_bucket = new_bucket;                   /* Prepared for install. */
     
    194194
    195195void
    196 sarray_at_put_safe(struct sarray* array, sidx index, void* element)
    197 {
    198   if(soffset_decode(index) >= array->capacity)
    199     sarray_realloc(array, soffset_decode(index)+1);
    200   sarray_at_put(array, index, element);
    201 }
    202 
    203 struct sarray*
    204 sarray_new (int size, void* default_element)
    205 {
    206   struct sarray* arr;
    207 #ifdef OBJC_SPARSE3
    208   size_t num_indices = ((size-1)/(INDEX_CAPACITY))+1;
    209   struct sindex ** new_indices;
    210 #else /* OBJC_SPARSE2 */
    211   size_t num_indices = ((size-1)/BUCKET_SIZE)+1;
    212   struct sbucket ** new_buckets;
    213 #endif
    214   int counter;
    215 
    216   assert(size > 0);
     196sarray_at_put_safe (struct sarray *array, sidx index, void *element)
     197{
     198  if (soffset_decode (index) >= array->capacity)
     199    sarray_realloc (array, soffset_decode (index) + 1);
     200  sarray_at_put (array, index, element);
     201}
     202
     203struct sarray *
     204sarray_new (int size, void *default_element)
     205{
     206  struct sarray *arr;
     207#ifdef OBJC_SPARSE3
     208  size_t num_indices = ((size - 1)/(INDEX_CAPACITY)) + 1;
     209  struct sindex **new_indices;
     210#else /* OBJC_SPARSE2 */
     211  size_t num_indices = ((size - 1)/BUCKET_SIZE) + 1;
     212  struct sbucket **new_buckets;
     213#endif
     214  size_t counter;
     215
     216  assert (size > 0);
    217217
    218218  /* Allocate core array */
    219   arr = (struct sarray*) objc_malloc(sizeof(struct sarray));
     219  arr = (struct sarray *) objc_malloc (sizeof (struct sarray));
    220220  arr->version.version = 0;
    221221 
     
    223223#ifdef OBJC_SPARSE3
    224224  arr->capacity = num_indices*INDEX_CAPACITY;
    225   new_indices = (struct sindex**)
    226     objc_malloc(sizeof(struct sindex*)*num_indices);
    227 
    228   arr->empty_index = (struct sindex*) objc_malloc(sizeof(struct sindex));
     225  new_indices = (struct sindex **)
     226    objc_malloc (sizeof (struct sindex *) * num_indices);
     227
     228  arr->empty_index = (struct sindex *) objc_malloc (sizeof (struct sindex));
    229229  arr->empty_index->version.version = 0;
    230230 
     
    235235#else /* OBJC_SPARSE2 */
    236236  arr->capacity = num_indices*BUCKET_SIZE;
    237   new_buckets = (struct sbucket**)
    238     objc_malloc(sizeof(struct sbucket*)*num_indices);
     237  new_buckets = (struct sbucket **)
     238    objc_malloc (sizeof (struct sbucket *) * num_indices);
    239239 
    240240  narrays  += 1;
     
    243243#endif
    244244
    245   arr->empty_bucket = (struct sbucket*) objc_malloc(sizeof(struct sbucket));
     245  arr->empty_bucket = (struct sbucket *) objc_malloc (sizeof (struct sbucket));
    246246  arr->empty_bucket->version.version = 0;
    247247 
     
    249249
    250250  arr->ref_count = 1;
    251   arr->is_copy_of = (struct sarray*)0;
    252  
    253   for (counter=0; counter<BUCKET_SIZE; counter++)
     251  arr->is_copy_of = (struct sarray *) 0;
     252 
     253  for (counter = 0; counter < BUCKET_SIZE; counter++)
    254254    arr->empty_bucket->elems[counter] = default_element;
    255255
    256256#ifdef OBJC_SPARSE3
    257   for (counter=0; counter<INDEX_SIZE; counter++)
     257  for (counter = 0; counter < INDEX_SIZE; counter++)
    258258    arr->empty_index->buckets[counter] = arr->empty_bucket;
    259259
    260   for (counter=0; counter<num_indices; counter++)
     260  for (counter = 0; counter < num_indices; counter++)
    261261    new_indices[counter] = arr->empty_index;
    262262
    263263#else /* OBJC_SPARSE2 */
    264264
    265   for (counter=0; counter<num_indices; counter++)
     265  for (counter = 0; counter < num_indices; counter++)
    266266    new_buckets[counter] = arr->empty_bucket;
    267267
     
    284284
    285285void
    286 sarray_realloc(struct sarray* array, int newsize)
    287 {
    288 #ifdef OBJC_SPARSE3
    289   size_t old_max_index = (array->capacity-1)/INDEX_CAPACITY;
    290   size_t new_max_index = ((newsize-1)/INDEX_CAPACITY);
    291   size_t rounded_size = (new_max_index+1)*INDEX_CAPACITY;
    292 
    293   struct sindex ** new_indices;
    294   struct sindex ** old_indices;
    295  
    296 #else /* OBJC_SPARSE2 */
    297   size_t old_max_index = (array->capacity-1)/BUCKET_SIZE;
    298   size_t new_max_index = ((newsize-1)/BUCKET_SIZE);
    299   size_t rounded_size = (new_max_index+1)*BUCKET_SIZE;
    300 
    301   struct sbucket ** new_buckets;
    302   struct sbucket ** old_buckets;
    303  
    304 #endif
    305 
    306   int counter;
    307 
    308   assert(newsize > 0);
     286sarray_realloc (struct sarray *array, int newsize)
     287{
     288#ifdef OBJC_SPARSE3
     289  size_t old_max_index = (array->capacity - 1)/INDEX_CAPACITY;
     290  size_t new_max_index = ((newsize - 1)/INDEX_CAPACITY);
     291  size_t rounded_size = (new_max_index + 1) * INDEX_CAPACITY;
     292
     293  struct sindex **new_indices;
     294  struct sindex **old_indices;
     295 
     296#else /* OBJC_SPARSE2 */
     297  size_t old_max_index = (array->capacity - 1)/BUCKET_SIZE;
     298  size_t new_max_index = ((newsize - 1)/BUCKET_SIZE);
     299  size_t rounded_size = (new_max_index + 1) * BUCKET_SIZE;
     300
     301  struct sbucket **new_buckets;
     302  struct sbucket **old_buckets;
     303 
     304#endif
     305
     306  size_t counter;
     307
     308  assert (newsize > 0);
    309309
    310310  /* The size is the same, just ignore the request */
    311   if(rounded_size <= array->capacity)
     311  if (rounded_size <= array->capacity)
    312312    return;
    313313
    314   assert(array->ref_count == 1);        /* stop if lazy copied... */
     314  assert (array->ref_count == 1);       /* stop if lazy copied... */
    315315
    316316  /* We are asked to extend the array -- allocate new bucket table, */
    317317  /* and insert empty_bucket in newly allocated places. */
    318   if(rounded_size > array->capacity)
     318  if (rounded_size > array->capacity)
    319319    {
    320320
    321321#ifdef OBJC_SPARSE3
    322322      new_max_index += 4;
    323       rounded_size = (new_max_index+1)*INDEX_CAPACITY;
     323      rounded_size = (new_max_index + 1) * INDEX_CAPACITY;
    324324     
    325325#else /* OBJC_SPARSE2 */
    326326      new_max_index += 4;
    327       rounded_size = (new_max_index+1)*BUCKET_SIZE;
     327      rounded_size = (new_max_index + 1) * BUCKET_SIZE;
    328328#endif
    329329     
     
    334334      /* alloc to force re-read by any concurrent readers. */
    335335      old_indices = array->indices;
    336       new_indices = (struct sindex**)
    337         objc_malloc((new_max_index+1)*sizeof(struct sindex*));
     336      new_indices = (struct sindex **)
     337        objc_malloc ((new_max_index + 1) * sizeof (struct sindex *));
    338338#else /* OBJC_SPARSE2 */
    339339      old_buckets = array->buckets;
    340       new_buckets = (struct sbucket**)
    341         objc_malloc((new_max_index+1)*sizeof(struct sbucket*));
     340      new_buckets = (struct sbucket **)
     341        objc_malloc ((new_max_index + 1) * sizeof (struct sbucket *));
    342342#endif
    343343
    344344      /* copy buckets below old_max_index (they are still valid) */
    345       for(counter = 0; counter <= old_max_index; counter++ ) {
     345      for (counter = 0; counter <= old_max_index; counter++ ) {
    346346#ifdef OBJC_SPARSE3
    347347        new_indices[counter] = old_indices[counter];
     
    353353#ifdef OBJC_SPARSE3
    354354      /* reset entries above old_max_index to empty_bucket */
    355       for(counter = old_max_index+1; counter <= new_max_index; counter++)
     355      for (counter = old_max_index + 1; counter <= new_max_index; counter++)
    356356        new_indices[counter] = array->empty_index;
    357357#else /* OBJC_SPARSE2 */
    358358      /* reset entries above old_max_index to empty_bucket */
    359       for(counter = old_max_index+1; counter <= new_max_index; counter++)
     359      for (counter = old_max_index + 1; counter <= new_max_index; counter++)
    360360        new_buckets[counter] = array->empty_bucket;
    361361#endif
     
    370370#ifdef OBJC_SPARSE3
    371371      /* free the old indices */
    372       sarray_free_garbage(old_indices);
    373 #else /* OBJC_SPARSE2 */
    374       sarray_free_garbage(old_buckets);
     372      sarray_free_garbage (old_indices);
     373#else /* OBJC_SPARSE2 */
     374      sarray_free_garbage (old_buckets);
    375375#endif
    376376     
     
    385385
    386386void
    387 sarray_free(struct sarray* array) {
    388 
    389 #ifdef OBJC_SPARSE3
    390   size_t old_max_index = (array->capacity-1)/INDEX_CAPACITY;
    391   struct sindex ** old_indices;
     387sarray_free (struct sarray *array) {
     388#ifdef OBJC_SPARSE3
     389  size_t old_max_index = (array->capacity - 1)/INDEX_CAPACITY;
     390  struct sindex **old_indices;
    392391#else
    393   size_t old_max_index = (array->capacity-1)/BUCKET_SIZE;
    394   struct sbucket ** old_buckets;
    395 #endif
    396   int counter = 0;
    397 
    398   assert(array->ref_count != 0);        /* Freed multiple times!!! */
    399 
    400   if(--(array->ref_count) != 0) /* There exists copies of me */
     392  size_t old_max_index = (array->capacity - 1)/BUCKET_SIZE;
     393  struct sbucket **old_buckets;
     394#endif
     395  size_t counter = 0;
     396
     397  assert (array->ref_count != 0);       /* Freed multiple times!!! */
     398
     399  if (--(array->ref_count) != 0)        /* There exists copies of me */
    401400    return;
    402401
     
    407406#endif
    408407 
    409   if((array->is_copy_of) && ((array->is_copy_of->ref_count - 1) == 0))
    410     sarray_free(array->is_copy_of);
     408  if ((array->is_copy_of) && ((array->is_copy_of->ref_count - 1) == 0))
     409    sarray_free (array->is_copy_of);
    411410
    412411  /* Free all entries that do not point to empty_bucket */
    413   for(counter = 0; counter <= old_max_index; counter++ ) {
    414 #ifdef OBJC_SPARSE3
    415     struct sindex* idx = old_indices[counter];
    416     if((idx != array->empty_index) &&
     412  for (counter = 0; counter <= old_max_index; counter++ ) {
     413#ifdef OBJC_SPARSE3
     414    struct sindex *idx = old_indices[counter];
     415    if ((idx != array->empty_index) &&
    417416       (idx->version.version == array->version.version)) {
    418417      int c2;
    419       for(c2=0; c2<INDEX_SIZE; c2++) {
    420         struct sbucket* bkt = idx->buckets[c2];
    421         if((bkt != array->empty_bucket) &&
     418      for (c2 = 0; c2 < INDEX_SIZE; c2++) {
     419        struct sbucket *bkt = idx->buckets[c2];
     420        if ((bkt != array->empty_bucket) &&
    422421           (bkt->version.version == array->version.version))
    423422          {
    424             sarray_free_garbage(bkt);
     423            sarray_free_garbage (bkt);
    425424            nbuckets -= 1;
    426425          }
    427426      }
    428       sarray_free_garbage(idx);
     427      sarray_free_garbage (idx);
    429428      nindices -= 1;
    430429    }
    431430#else /* OBJC_SPARSE2 */
    432     struct sbucket* bkt = array->buckets[counter];
     431    struct sbucket *bkt = array->buckets[counter];
    433432    if ((bkt != array->empty_bucket) &&
    434433        (bkt->version.version == array->version.version))
    435434      {
    436         sarray_free_garbage(bkt);
     435        sarray_free_garbage (bkt);
    437436        nbuckets -= 1;
    438437      }
     
    442441#ifdef OBJC_SPARSE3 
    443442  /* free empty_index */
    444   if(array->empty_index->version.version == array->version.version) {
    445     sarray_free_garbage(array->empty_index);
     443  if (array->empty_index->version.version == array->version.version) {
     444    sarray_free_garbage (array->empty_index);
    446445    nindices -= 1;
    447446  }
     
    449448
    450449  /* free empty_bucket */
    451   if(array->empty_bucket->version.version == array->version.version) {
    452     sarray_free_garbage(array->empty_bucket);
     450  if (array->empty_bucket->version.version == array->version.version) {
     451    sarray_free_garbage (array->empty_bucket);
    453452    nbuckets -= 1;
    454453  }
    455   idxsize -= (old_max_index+1);
     454  idxsize -= (old_max_index + 1);
    456455  narrays -= 1;
    457456
    458457#ifdef OBJC_SPARSE3
    459458  /* free bucket table */
    460   sarray_free_garbage(array->indices);
     459  sarray_free_garbage (array->indices);
    461460
    462461#else
    463462  /* free bucket table */
    464   sarray_free_garbage(array->buckets);
     463  sarray_free_garbage (array->buckets);
    465464
    466465#endif
    467466 
    468467  /* free array */
    469   sarray_free_garbage(array);
     468  sarray_free_garbage (array);
    470469}
    471470
     
    473472/* copied.   */
    474473
    475 struct sarray*
    476 sarray_lazy_copy(struct sarray* oarr)
    477 {
    478   struct sarray* arr;
    479 
    480 #ifdef OBJC_SPARSE3
    481   size_t num_indices = ((oarr->capacity-1)/INDEX_CAPACITY)+1;
    482   struct sindex ** new_indices;
    483 #else /* OBJC_SPARSE2 */
    484   size_t num_indices = ((oarr->capacity-1)/BUCKET_SIZE)+1;
    485   struct sbucket ** new_buckets;
     474struct sarray *
     475sarray_lazy_copy (struct sarray *oarr)
     476{
     477  struct sarray *arr;
     478
     479#ifdef OBJC_SPARSE3
     480  size_t num_indices = ((oarr->capacity - 1)/INDEX_CAPACITY) + 1;
     481  struct sindex **new_indices;
     482#else /* OBJC_SPARSE2 */
     483  size_t num_indices = ((oarr->capacity - 1)/BUCKET_SIZE) + 1;
     484  struct sbucket **new_buckets;
    486485#endif
    487486
    488487  /* Allocate core array */
    489   arr = (struct sarray*) objc_malloc(sizeof(struct sarray)); /* !!! */
     488  arr = (struct sarray *) objc_malloc (sizeof (struct sarray)); /* !!! */
    490489  arr->version.version = oarr->version.version + 1;
    491490#ifdef OBJC_SPARSE3
     
    500499#ifdef OBJC_SPARSE3
    501500  /* Copy bucket table */
    502   new_indices = (struct sindex**)
    503     objc_malloc(sizeof(struct sindex*)*num_indices);
    504   memcpy( new_indices,oarr->indices,
    505         sizeof(struct sindex*)*num_indices);
     501  new_indices = (struct sindex **)
     502    objc_malloc (sizeof (struct sindex *) * num_indices);
     503  memcpy (new_indices, oarr->indices, sizeof (struct sindex *) * num_indices);
    506504  arr->indices = new_indices;
    507505#else
    508506  /* Copy bucket table */
    509   new_buckets = (struct sbucket**)
    510     objc_malloc(sizeof(struct sbucket*)*num_indices);
    511   memcpy( new_buckets,oarr->buckets,
    512         sizeof(struct sbucket*)*num_indices);
     507  new_buckets = (struct sbucket **)
     508    objc_malloc (sizeof (struct sbucket *) * num_indices);
     509  memcpy (new_buckets, oarr->buckets, sizeof (struct sbucket *) * num_indices);
    513510  arr->buckets = new_buckets;
    514511#endif
Note: See TracChangeset for help on using the changeset viewer.