Пример #1
0
/* Insert a class in the table (used when a new class is
   registered).  */
static void 
class_table_insert (const char *class_name, Class class_pointer)
{
  int hash, length;
  class_node_ptr new_node;

  /* Find out the class name's hash and length.  */
  CLASS_TABLE_HASH (length, hash, class_name);
  
  /* Prepare the new node holding the class.  */
  new_node = objc_malloc (sizeof (struct class_node));
  new_node->name = class_name;
  new_node->length = length;
  new_node->pointer = class_pointer;

  /* Lock the table for modifications.  */
  objc_mutex_lock (__class_table_lock);
  
  /* Insert the new node in the table at the beginning of the table at
     class_table_array[hash].  */
  new_node->next = class_table_array[hash];
  class_table_array[hash] = new_node;
  
  objc_mutex_unlock (__class_table_lock);
}
Пример #2
0
static inline Class class_table_get_safe(const char* class_name)
{
    class_node_ptr node;
    int length,
        hash;

    CLASS_TABLE_HASH(length, hash, class_name);

    node = class_table_array[hash];

    if ( node != NULL ) {
        do {
            if ( node->length == length ) {
                int i;

                for ( i = 0; i < length; ++ i ) {
                    if ( (node->name)[i] != class_name[i] )
                        break;
                }

                if ( i == length )
                    return node->pointer;
            }
        } while ( ( node = node->next ) != NULL );
    }
    return Nil;
}
Пример #3
0
static void class_table_insert(const char* class_name, Class class_pointer)
{
    int hash,
        length;
    class_node_ptr new_node;

    CLASS_TABLE_HASH(length, hash, class_name);

    new_node = tour_malloc( sizeof(struct class_node) );
    new_node->name = class_name;
    new_node->length = length;
    new_node->pointer = class_pointer;

    tour_mutex_lock( __class_table_lock );

    new_node->next = class_table_array[hash];
    class_table_array[hash] = new_node;

    tour_mutex_unlock( __class_table_lock );
}
Пример #4
0
Файл: class.c Проект: aosm/gcc3
/* Get a class from the table.  This does not need mutex protection.
   Currently, this function is called each time you call a static
   method, this is why it must be very fast.  */
static inline Class 
class_table_get_safe (const char *class_name)
{
  class_node_ptr node;  
  int length, hash;

  /* Compute length and hash.  */
  CLASS_TABLE_HASH (length, hash, class_name);
  
  node = class_table_array[hash];
  
  if (node != NULL)
    {
      do
        {
          if (node->length == length)
            {
              /* Compare the class names.  */
              int i;

              for (i = 0; i < length; i++)
                {
                  if ((node->name)[i] != class_name[i]) 
                    {
                      break;
                    }
                }
              
              if (i == length)
                {
                  /* They are equal!  */
                  return node->pointer;
                }
            }
        }
      while ((node = node->next) != NULL);
    }

  return Nil;
}