Commit 40165636 by Rodney Brown Committed by Stan Shebs

encoding.h: Fix formatting.

2002-07-02  Rodney Brown  <rbrown64@csc.com.au>

	* objc/encoding.h: Fix formatting.
	* objc/hash.h: Likewise.
	* objc/objc-api.h: Likewise.
	* objc/runtime.h: Likewise.
	* objc/thr.h: Likewise.
	* archive.c: Likewise.
	* class.c: Likewise.
	* encoding.c: Likewise.
	* gc.c: Likewise.
	* hash.c: Likewise.
	* init.c: Likewise.
	* misc.c: Likewise.
	* nil_method.c: Likewise.
	* objects.c: Likewise.
	* sarray.c: Likewise.
	* selector.c: Likewise.
	* sendmsg.c: Likewise.
	* thr-mach.c: Likewise.
	* thr.c: Likewise.

From-SVN: r55190
parent 52702ae1
2002-07-02 Rodney Brown <rbrown64@csc.com.au>
* objc/encoding.h: Fix formatting.
* objc/hash.h: Likewise.
* objc/objc-api.h: Likewise.
* objc/runtime.h: Likewise.
* objc/thr.h: Likewise.
* archive.c: Likewise.
* class.c: Likewise.
* encoding.c: Likewise.
* gc.c: Likewise.
* hash.c: Likewise.
* init.c: Likewise.
* misc.c: Likewise.
* nil_method.c: Likewise.
* objects.c: Likewise.
* sarray.c: Likewise.
* selector.c: Likewise.
* sendmsg.c: Likewise.
* thr-mach.c: Likewise.
* thr.c: Likewise.
2002-06-25 DJ Delorie <dj@redhat.com> 2002-06-25 DJ Delorie <dj@redhat.com>
* aclocal.m4 (GLIBCPP_CONFIGURE): Split out * aclocal.m4 (GLIBCPP_CONFIGURE): Split out
......
/* GNU Objective C Runtime class related functions /* GNU Objective C Runtime class related functions
Copyright (C) 1993, 1995, 1996, 1997, 2001 Free Software Foundation, Inc. Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002
Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup and Dennis Glatting. Contributed by Kresten Krab Thorup and Dennis Glatting.
Lock-free class table code designed and written from scratch by Lock-free class table code designed and written from scratch by
...@@ -166,7 +167,7 @@ static void ...@@ -166,7 +167,7 @@ static void
class_table_setup (void) class_table_setup (void)
{ {
/* Start - nothing in the table. */ /* Start - nothing in the table. */
memset (class_table_array, 0, sizeof(class_node_ptr) * CLASS_TABLE_SIZE); memset (class_table_array, 0, sizeof (class_node_ptr) * CLASS_TABLE_SIZE);
/* The table writing mutex. */ /* The table writing mutex. */
__class_table_lock = objc_mutex_allocate (); __class_table_lock = objc_mutex_allocate ();
...@@ -339,7 +340,7 @@ class_table_next (struct class_table_enumerator **e) ...@@ -339,7 +340,7 @@ class_table_next (struct class_table_enumerator **e)
#if 0 /* DEBUGGING FUNCTIONS */ #if 0 /* DEBUGGING FUNCTIONS */
/* Debugging function - print the class table. */ /* Debugging function - print the class table. */
void void
class_table_print () class_table_print (void)
{ {
int i; int i;
...@@ -362,7 +363,7 @@ class_table_print () ...@@ -362,7 +363,7 @@ class_table_print ()
function of hash key values. Useful to evaluate the hash function function of hash key values. Useful to evaluate the hash function
in real cases. */ in real cases. */
void void
class_table_print_histogram () class_table_print_histogram (void)
{ {
int i, j; int i, j;
int counter = 0; int counter = 0;
...@@ -408,64 +409,66 @@ class_table_print_histogram () ...@@ -408,64 +409,66 @@ class_table_print_histogram ()
/* This is a hook which is called by objc_get_class and /* This is a hook which is called by objc_get_class and
objc_lookup_class if the runtime is not able to find the class. objc_lookup_class if the runtime is not able to find the class.
This may e.g. try to load in the class using dynamic loading. */ This may e.g. try to load in the class using dynamic loading. */
Class (*_objc_lookup_class)(const char* name) = 0; /* !T:SAFE */ Class (*_objc_lookup_class) (const char *name) = 0; /* !T:SAFE */
/* True when class links has been resolved. */ /* True when class links has been resolved. */
BOOL __objc_class_links_resolved = NO; /* !T:UNUSED */ BOOL __objc_class_links_resolved = NO; /* !T:UNUSED */
void __objc_init_class_tables() void
__objc_init_class_tables (void)
{ {
/* Allocate the class hash table. */ /* Allocate the class hash table. */
if(__class_table_lock) if (__class_table_lock)
return; return;
objc_mutex_lock(__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
class_table_setup (); class_table_setup ();
objc_mutex_unlock(__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
} }
/* This function adds a class to the class hash table, and assigns the /* This function adds a class to the class hash table, and assigns the
class a number, unless it's already known. */ class a number, unless it's already known. */
void void
__objc_add_class_to_hash(Class class) __objc_add_class_to_hash (Class class)
{ {
Class h_class; Class h_class;
objc_mutex_lock(__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* Make sure the table is there. */ /* Make sure the table is there. */
assert(__class_table_lock); assert (__class_table_lock);
/* Make sure it's not a meta class. */ /* Make sure it's not a meta class. */
assert(CLS_ISCLASS(class)); assert (CLS_ISCLASS (class));
/* Check to see if the class is already in the hash table. */ /* Check to see if the class is already in the hash table. */
h_class = class_table_get_safe (class->name); h_class = class_table_get_safe (class->name);
if (!h_class) if (! h_class)
{ {
/* The class isn't in the hash table. Add the class and assign a class /* The class isn't in the hash table. Add the class and assign a class
number. */ number. */
static unsigned int class_number = 1; static unsigned int class_number = 1;
CLS_SETNUMBER(class, class_number); CLS_SETNUMBER (class, class_number);
CLS_SETNUMBER(class->class_pointer, class_number); CLS_SETNUMBER (class->class_pointer, class_number);
++class_number; ++class_number;
class_table_insert (class->name, class); class_table_insert (class->name, class);
} }
objc_mutex_unlock(__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
} }
/* Get the class object for the class named NAME. If NAME does not /* Get the class object for the class named NAME. If NAME does not
identify a known class, the hook _objc_lookup_class is called. If identify a known class, the hook _objc_lookup_class is called. If
this fails, nil is returned. */ this fails, nil is returned. */
Class objc_lookup_class (const char* name) Class
objc_lookup_class (const char *name)
{ {
Class class; Class class;
...@@ -475,7 +478,7 @@ Class objc_lookup_class (const char* name) ...@@ -475,7 +478,7 @@ Class objc_lookup_class (const char* name)
return class; return class;
if (_objc_lookup_class) if (_objc_lookup_class)
return (*_objc_lookup_class)(name); return (*_objc_lookup_class) (name);
else else
return 0; return 0;
} }
...@@ -494,20 +497,20 @@ objc_get_class (const char *name) ...@@ -494,20 +497,20 @@ objc_get_class (const char *name)
return class; return class;
if (_objc_lookup_class) if (_objc_lookup_class)
class = (*_objc_lookup_class)(name); class = (*_objc_lookup_class) (name);
if(class) if (class)
return class; return class;
objc_error(nil, OBJC_ERR_BAD_CLASS, objc_error (nil, OBJC_ERR_BAD_CLASS,
"objc runtime: cannot find class %s\n", name); "objc runtime: cannot find class %s\n", name);
return 0; return 0;
} }
MetaClass MetaClass
objc_get_meta_class(const char *name) objc_get_meta_class (const char *name)
{ {
return objc_get_class(name)->class_pointer; return objc_get_class (name)->class_pointer;
} }
/* This function provides a way to enumerate all the classes in the /* This function provides a way to enumerate all the classes in the
...@@ -516,22 +519,22 @@ objc_get_meta_class(const char *name) ...@@ -516,22 +519,22 @@ objc_get_meta_class(const char *name)
For example: For example:
id class; id class;
void *es = NULL; void *es = NULL;
while ((class = objc_next_class(&es))) while ((class = objc_next_class (&es)))
... do something with class; ... do something with class;
*/ */
Class Class
objc_next_class(void **enum_state) objc_next_class (void **enum_state)
{ {
Class class; Class class;
objc_mutex_lock(__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* Make sure the table is there. */ /* Make sure the table is there. */
assert(__class_table_lock); assert (__class_table_lock);
class = class_table_next ((struct class_table_enumerator **)enum_state); class = class_table_next ((struct class_table_enumerator **) enum_state);
objc_mutex_unlock(__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
return class; return class;
} }
...@@ -539,33 +542,34 @@ objc_next_class(void **enum_state) ...@@ -539,33 +542,34 @@ objc_next_class(void **enum_state)
/* Resolve super/subclass links for all classes. The only thing we /* Resolve super/subclass links for all classes. The only thing we
can be sure of is that the class_pointer for class objects point to can be sure of is that the class_pointer for class objects point to
the right meta class objects. */ the right meta class objects. */
void __objc_resolve_class_links() void
__objc_resolve_class_links (void)
{ {
struct class_table_enumerator *es = NULL; struct class_table_enumerator *es = NULL;
Class object_class = objc_get_class ("Object"); Class object_class = objc_get_class ("Object");
Class class1; Class class1;
assert(object_class); assert (object_class);
objc_mutex_lock(__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* Assign subclass links. */ /* Assign subclass links. */
while ((class1 = class_table_next (&es))) while ((class1 = class_table_next (&es)))
{ {
/* Make sure we have what we think we have. */ /* Make sure we have what we think we have. */
assert (CLS_ISCLASS(class1)); assert (CLS_ISCLASS (class1));
assert (CLS_ISMETA(class1->class_pointer)); assert (CLS_ISMETA (class1->class_pointer));
/* The class_pointer of all meta classes point to Object's meta /* The class_pointer of all meta classes point to Object's meta
class. */ class. */
class1->class_pointer->class_pointer = object_class->class_pointer; class1->class_pointer->class_pointer = object_class->class_pointer;
if (!(CLS_ISRESOLV(class1))) if (! CLS_ISRESOLV (class1))
{ {
CLS_SETRESOLV(class1); CLS_SETRESOLV (class1);
CLS_SETRESOLV(class1->class_pointer); CLS_SETRESOLV (class1->class_pointer);
if(class1->super_class) if (class1->super_class)
{ {
Class a_super_class Class a_super_class
= objc_get_class ((char *) class1->super_class); = objc_get_class ((char *) class1->super_class);
...@@ -607,12 +611,12 @@ void __objc_resolve_class_links() ...@@ -607,12 +611,12 @@ void __objc_resolve_class_links()
sub_class = sub_class->sibling_class) sub_class = sub_class->sibling_class)
{ {
sub_class->super_class = class1; sub_class->super_class = class1;
if(CLS_ISCLASS(sub_class)) if (CLS_ISCLASS (sub_class))
sub_class->class_pointer->super_class = class1->class_pointer; sub_class->class_pointer->super_class = class1->class_pointer;
} }
} }
objc_mutex_unlock(__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
} }
...@@ -622,7 +626,7 @@ void __objc_resolve_class_links() ...@@ -622,7 +626,7 @@ void __objc_resolve_class_links()
Class Class
class_pose_as (Class impostor, Class super_class) class_pose_as (Class impostor, Class super_class)
{ {
if (!CLS_ISRESOLV (impostor)) if (! CLS_ISRESOLV (impostor))
__objc_resolve_class_links (); __objc_resolve_class_links ();
/* Preconditions */ /* Preconditions */
...@@ -685,11 +689,11 @@ class_pose_as (Class impostor, Class super_class) ...@@ -685,11 +689,11 @@ class_pose_as (Class impostor, Class super_class)
keys of the hashtable is, change all values that are superclass keys of the hashtable is, change all values that are superclass
into impostor. */ into impostor. */
objc_mutex_lock(__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
class_table_replace (super_class, impostor); class_table_replace (super_class, impostor);
objc_mutex_unlock(__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
/* Next, we update the dispatch tables... */ /* Next, we update the dispatch tables... */
__objc_update_dispatch_table_for_class (CLASSOF (impostor)); __objc_update_dispatch_table_for_class (CLASSOF (impostor));
......
/* Basic data types for Objective C. /* Basic data types for Objective C.
Copyright (C) 1998 Free Software Foundation, Inc. Copyright (C) 1998, 2002 Free Software Foundation, Inc.
Contributed by Ovidiu Predescu. Contributed by Ovidiu Predescu.
This file is part of GNU CC. This file is part of GNU CC.
...@@ -58,11 +58,11 @@ typedef GC_signed_word signed_word; ...@@ -58,11 +58,11 @@ typedef GC_signed_word signed_word;
The offset is incremented with the size of the type. */ The offset is incremented with the size of the type. */
#define ROUND(V, A) \ #define ROUND(V, A) \
({ typeof(V) __v=(V); typeof(A) __a=(A); \ ({ typeof (V) __v = (V); typeof (A) __a = (A); \
__a*((__v+__a-1)/__a); }) __a * ((__v+__a - 1)/__a); })
#define SET_BIT_FOR_OFFSET(mask, offset) \ #define SET_BIT_FOR_OFFSET(mask, offset) \
GC_set_bit(mask, offset / sizeof (void*)) GC_set_bit (mask, offset / sizeof (void *))
/* Some prototypes */ /* Some prototypes */
static void static void
...@@ -74,9 +74,9 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset); ...@@ -74,9 +74,9 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset);
static void static void
__objc_gc_setup_array (GC_bitmap mask, const char *type, int offset) __objc_gc_setup_array (GC_bitmap mask, const char *type, int offset)
{ {
int i, len = atoi(type + 1); int i, len = atoi (type + 1);
while (isdigit(*++type)) while (isdigit (*++type))
/* do nothing */; /* skip the size of the array */ /* do nothing */; /* skip the size of the array */
switch (*type) { switch (*type) {
...@@ -138,8 +138,8 @@ __objc_gc_setup_struct (GC_bitmap mask, const char *type, int offset) ...@@ -138,8 +138,8 @@ __objc_gc_setup_struct (GC_bitmap mask, const char *type, int offset)
case _C_PTR: case _C_PTR:
case _C_CHARPTR: case _C_CHARPTR:
case _C_ATOM: case _C_ATOM:
if (!gc_invisible) if (! gc_invisible)
SET_BIT_FOR_OFFSET(mask, position); SET_BIT_FOR_OFFSET (mask, position);
break; break;
case _C_ARY_B: case _C_ARY_B:
...@@ -178,11 +178,11 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset) ...@@ -178,11 +178,11 @@ __objc_gc_setup_union (GC_bitmap mask, const char *type, int offset)
size = objc_sizeof_type (type); size = objc_sizeof_type (type);
align = objc_alignof_type (type); align = objc_alignof_type (type);
offset = ROUND(offset, align); offset = ROUND (offset, align);
for (i = 0; i < size; i += sizeof (void*)) for (i = 0; i < size; i += sizeof (void *))
{ {
SET_BIT_FOR_OFFSET(mask, offset); SET_BIT_FOR_OFFSET (mask, offset);
offset += sizeof (void*); offset += sizeof (void *);
} }
} }
...@@ -223,8 +223,8 @@ __objc_gc_type_description_from_type (GC_bitmap mask, const char *type) ...@@ -223,8 +223,8 @@ __objc_gc_type_description_from_type (GC_bitmap mask, const char *type)
case _C_SEL: case _C_SEL:
case _C_PTR: case _C_PTR:
case _C_CHARPTR: case _C_CHARPTR:
if (!gc_invisible) if (! gc_invisible)
SET_BIT_FOR_OFFSET(mask, offset); SET_BIT_FOR_OFFSET (mask, offset);
break; break;
case _C_ARY_B: case _C_ARY_B:
...@@ -254,9 +254,9 @@ __objc_class_structure_encoding (Class class, char **type, int *size, ...@@ -254,9 +254,9 @@ __objc_class_structure_encoding (Class class, char **type, int *size,
int *current) int *current)
{ {
int i, ivar_count; int i, ivar_count;
struct objc_ivar_list* ivars; struct objc_ivar_list *ivars;
if (!class) if (! class)
{ {
strcat (*type, "{"); strcat (*type, "{");
*current++; *current++;
...@@ -267,7 +267,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size, ...@@ -267,7 +267,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size,
__objc_class_structure_encoding (class->super_class, type, size, current); __objc_class_structure_encoding (class->super_class, type, size, current);
ivars = class->ivars; ivars = class->ivars;
if (!ivars) if (! ivars)
return; return;
ivar_count = ivars->ivar_count; ivar_count = ivars->ivar_count;
...@@ -282,7 +282,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size, ...@@ -282,7 +282,7 @@ __objc_class_structure_encoding (Class class, char **type, int *size,
{ {
/* Increase the size of the encoding string so that it /* Increase the size of the encoding string so that it
contains this ivar's type. */ contains this ivar's type. */
*size = ROUND(*current + len + 1, 10); *size = ROUND (*current + len + 1, 10);
*type = objc_realloc (*type, *size); *type = objc_realloc (*type, *size);
} }
strcat (*type + *current, ivar_type); strcat (*type + *current, ivar_type);
...@@ -302,7 +302,7 @@ __objc_generate_gc_type_description (Class class) ...@@ -302,7 +302,7 @@ __objc_generate_gc_type_description (Class class)
int type_size = 10, current; int type_size = 10, current;
char *class_structure_type; char *class_structure_type;
if (!CLS_ISCLASS(class)) if (! CLS_ISCLASS (class))
return; return;
/* We have to create a mask in which each bit counts for a pointer member. /* We have to create a mask in which each bit counts for a pointer member.
...@@ -311,9 +311,9 @@ __objc_generate_gc_type_description (Class class) ...@@ -311,9 +311,9 @@ __objc_generate_gc_type_description (Class class)
/* The number of bits in the mask is the size of an instance in bytes divided /* The number of bits in the mask is the size of an instance in bytes divided
by the size of a pointer. */ by the size of a pointer. */
bits_no = (ROUND(class_get_instance_size (class), sizeof(void*)) bits_no = (ROUND (class_get_instance_size (class), sizeof (void *))
/ sizeof (void*)); / sizeof (void *));
size = ROUND(bits_no, BITS_PER_WORD) / BITS_PER_WORD; size = ROUND (bits_no, BITS_PER_WORD) / BITS_PER_WORD;
mask = objc_atomic_malloc (size * sizeof (int)); mask = objc_atomic_malloc (size * sizeof (int));
memset (mask, 0, size * sizeof (int)); memset (mask, 0, size * sizeof (int));
...@@ -342,7 +342,7 @@ __objc_generate_gc_type_description (Class class) ...@@ -342,7 +342,7 @@ __objc_generate_gc_type_description (Class class)
puts (""); puts ("");
#endif #endif
class->gc_object_type = (void*)GC_make_descriptor (mask, bits_no); class->gc_object_type = (void *) GC_make_descriptor (mask, bits_no);
} }
...@@ -370,17 +370,17 @@ __objc_ivar_pointer (const char *type) ...@@ -370,17 +370,17 @@ __objc_ivar_pointer (const char *type)
This operation only makes sense on instance variables that are This operation only makes sense on instance variables that are
pointers. */ pointers. */
void void
class_ivar_set_gcinvisible (Class class, const char* ivarname, class_ivar_set_gcinvisible (Class class, const char *ivarname,
BOOL gc_invisible) BOOL gc_invisible)
{ {
int i, ivar_count; int i, ivar_count;
struct objc_ivar_list* ivars; struct objc_ivar_list *ivars;
if (!class || !ivarname) if (! class || ! ivarname)
return; return;
ivars = class->ivars; ivars = class->ivars;
if (!ivars) if (! ivars)
return; return;
ivar_count = ivars->ivar_count; ivar_count = ivars->ivar_count;
...@@ -390,7 +390,7 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname, ...@@ -390,7 +390,7 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname,
struct objc_ivar *ivar = &(ivars->ivar_list[i]); struct objc_ivar *ivar = &(ivars->ivar_list[i]);
const char *type; const char *type;
if (!ivar->ivar_name || strcmp (ivar->ivar_name, ivarname)) if (! ivar->ivar_name || strcmp (ivar->ivar_name, ivarname))
continue; continue;
assert (ivar->ivar_type); assert (ivar->ivar_type);
...@@ -407,7 +407,7 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname, ...@@ -407,7 +407,7 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname,
{ {
char *new_type; char *new_type;
if (gc_invisible || !__objc_ivar_pointer (type)) if (gc_invisible || ! __objc_ivar_pointer (type))
return; /* The type of the variable already matches the return; /* The type of the variable already matches the
requested gc_invisible type */ requested gc_invisible type */
...@@ -422,7 +422,7 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname, ...@@ -422,7 +422,7 @@ class_ivar_set_gcinvisible (Class class, const char* ivarname,
{ {
char *new_type; char *new_type;
if (!gc_invisible || !__objc_ivar_pointer (type)) if (! gc_invisible || ! __objc_ivar_pointer (type))
return; /* The type of the variable already matches the return; /* The type of the variable already matches the
requested gc_invisible type */ requested gc_invisible type */
...@@ -451,7 +451,7 @@ __objc_generate_gc_type_description (Class class __attribute__ ((__unused__))) ...@@ -451,7 +451,7 @@ __objc_generate_gc_type_description (Class class __attribute__ ((__unused__)))
} }
void class_ivar_set_gcinvisible (Class class __attribute__ ((__unused__)), void class_ivar_set_gcinvisible (Class class __attribute__ ((__unused__)),
const char* ivarname __attribute__ ((__unused__)), const char *ivarname __attribute__ ((__unused__)),
BOOL gc_invisible __attribute__ ((__unused__))) BOOL gc_invisible __attribute__ ((__unused__)))
{ {
} }
......
...@@ -47,7 +47,7 @@ hash_new (unsigned int size, hash_func_type hash_func, ...@@ -47,7 +47,7 @@ hash_new (unsigned int size, hash_func_type hash_func,
/* Pass me a value greater than 0 and a power of 2. */ /* Pass me a value greater than 0 and a power of 2. */
assert (size); assert (size);
assert (!(size & (size - 1))); assert (! (size & (size - 1)));
/* Allocate the cache structure. calloc insures /* Allocate the cache structure. calloc insures
its initialization for default values. */ its initialization for default values. */
...@@ -196,7 +196,7 @@ hash_remove (cache_ptr cache, const void *key) ...@@ -196,7 +196,7 @@ hash_remove (cache_ptr cache, const void *key)
objc_free(node); objc_free(node);
} else } else
prev = node, node = node->next; prev = node, node = node->next;
} while (!removed && node); } while (! removed && node);
assert (removed); assert (removed);
} }
...@@ -210,7 +210,7 @@ hash_next (cache_ptr cache, node_ptr node) ...@@ -210,7 +210,7 @@ hash_next (cache_ptr cache, node_ptr node)
{ {
/* If the scan is being started then reset the last node /* If the scan is being started then reset the last node
visitied pointer and bucket index. */ visitied pointer and bucket index. */
if (!node) if (! node)
cache->last_bucket = 0; cache->last_bucket = 0;
/* If there is a node visited last then check for another /* If there is a node visited last then check for another
...@@ -258,7 +258,7 @@ hash_value_for_key (cache_ptr cache, const void *key) ...@@ -258,7 +258,7 @@ hash_value_for_key (cache_ptr cache, const void *key)
break; break;
} else } else
node = node->next; node = node->next;
} while (!retval && node); } while (! retval && node);
return retval; return retval;
} }
......
/* GNU Objective C Runtime Miscellaneous /* GNU Objective C Runtime Miscellaneous
Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002
Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup Contributed by Kresten Krab Thorup
This file is part of GNU CC. This file is part of GNU CC.
...@@ -37,25 +38,25 @@ static objc_error_handler _objc_error_handler = NULL; ...@@ -37,25 +38,25 @@ static objc_error_handler _objc_error_handler = NULL;
/* Trigger an objc error */ /* Trigger an objc error */
void void
objc_error(id object, int code, const char* fmt, ...) objc_error (id object, int code, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start (ap, fmt);
objc_verror(object, code, fmt, ap); objc_verror (object, code, fmt, ap);
va_end(ap); va_end (ap);
} }
/* Trigger an objc error */ /* Trigger an objc error */
void void
objc_verror(id object, int code, const char* fmt, va_list ap) objc_verror (id object, int code, const char *fmt, va_list ap)
{ {
BOOL result = NO; BOOL result = NO;
/* Call the error handler if its there /* Call the error handler if its there
Otherwise print to stderr */ Otherwise print to stderr */
if (_objc_error_handler) if (_objc_error_handler)
result = (*_objc_error_handler)(object, code, fmt, ap); result = (*_objc_error_handler) (object, code, fmt, ap);
else else
vfprintf (stderr, fmt, ap); vfprintf (stderr, fmt, ap);
...@@ -64,12 +65,12 @@ objc_verror(id object, int code, const char* fmt, va_list ap) ...@@ -64,12 +65,12 @@ objc_verror(id object, int code, const char* fmt, va_list ap)
if (result) if (result)
return; return;
else else
abort(); abort ();
} }
/* Set the error handler */ /* Set the error handler */
objc_error_handler objc_error_handler
objc_set_error_handler(objc_error_handler func) objc_set_error_handler (objc_error_handler func)
{ {
objc_error_handler temp = _objc_error_handler; objc_error_handler temp = _objc_error_handler;
_objc_error_handler = func; _objc_error_handler = func;
...@@ -84,54 +85,54 @@ objc_set_error_handler(objc_error_handler func) ...@@ -84,54 +85,54 @@ objc_set_error_handler(objc_error_handler func)
*/ */
void * void *
objc_malloc(size_t size) objc_malloc (size_t size)
{ {
void* res = (void*) (*_objc_malloc)(size); void *res = (void *) (*_objc_malloc) (size);
if(!res) if (! res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res; return res;
} }
void * void *
objc_atomic_malloc(size_t size) objc_atomic_malloc (size_t size)
{ {
void* res = (void*) (*_objc_atomic_malloc)(size); void *res = (void *) (*_objc_atomic_malloc) (size);
if(!res) if (! res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res; return res;
} }
void * void *
objc_valloc(size_t size) objc_valloc (size_t size)
{ {
void* res = (void*) (*_objc_valloc)(size); void *res = (void *) (*_objc_valloc) (size);
if(!res) if (! res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res; return res;
} }
void * void *
objc_realloc(void *mem, size_t size) objc_realloc (void *mem, size_t size)
{ {
void* res = (void*) (*_objc_realloc)(mem, size); void *res = (void *) (*_objc_realloc) (mem, size);
if(!res) if (! res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res; return res;
} }
void * void *
objc_calloc(size_t nelem, size_t size) objc_calloc (size_t nelem, size_t size)
{ {
void* res = (void*) (*_objc_calloc)(nelem, size); void *res = (void *) (*_objc_calloc) (nelem, size);
if(!res) if (! res)
objc_error(nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n"); objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
return res; return res;
} }
void void
objc_free(void *mem) objc_free (void *mem)
{ {
(*_objc_free)(mem); (*_objc_free) (mem);
} }
/* /*
...@@ -148,33 +149,37 @@ objc_free(void *mem) ...@@ -148,33 +149,37 @@ objc_free(void *mem)
#if OBJC_WITH_GC #if OBJC_WITH_GC
#include <gc.h> #include <gc.h>
static void *GC_calloc (size_t nelem, size_t size) static void *
GC_calloc (size_t nelem, size_t size)
{ {
void* p = GC_malloc (nelem * size); void *p = GC_malloc (nelem * size);
if (!p) if (! p)
objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted!\n"); objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted!\n");
memset (p, 0, nelem * size); memset (p, 0, nelem * size);
return p; return p;
} }
static void noFree (void* p) {} static void
noFree (void *p)
{
}
void *(*_objc_malloc)(size_t) = GC_malloc; void *(*_objc_malloc) (size_t) = GC_malloc;
void *(*_objc_atomic_malloc)(size_t) = GC_malloc_atomic; void *(*_objc_atomic_malloc) (size_t) = GC_malloc_atomic;
void *(*_objc_valloc)(size_t) = GC_malloc; void *(*_objc_valloc) (size_t) = GC_malloc;
void *(*_objc_realloc)(void *, size_t) = GC_realloc; void *(*_objc_realloc) (void *, size_t) = GC_realloc;
void *(*_objc_calloc)(size_t, size_t) = GC_calloc; void *(*_objc_calloc) (size_t, size_t) = GC_calloc;
void (*_objc_free)(void *) = noFree; void (*_objc_free) (void *) = noFree;
#else #else /* !OBJC_WITH_GC */
void *(*_objc_malloc)(size_t) = malloc; void *(*_objc_malloc) (size_t) = malloc;
void *(*_objc_atomic_malloc)(size_t) = malloc; void *(*_objc_atomic_malloc) (size_t) = malloc;
void *(*_objc_valloc)(size_t) = malloc; void *(*_objc_valloc) (size_t) = malloc;
void *(*_objc_realloc)(void *, size_t) = realloc; void *(*_objc_realloc) (void *, size_t) = realloc;
void *(*_objc_calloc)(size_t, size_t) = calloc; void *(*_objc_calloc) (size_t, size_t) = calloc;
void (*_objc_free)(void *) = free; void (*_objc_free) (void *) = free;
#endif #endif /* !OBJC_WITH_GC */
/* GNU Objective C Runtime nil receiver function /* GNU Objective C Runtime nil receiver function
Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc. Copyright (C) 1993, 1995, 1996, 2002 Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup Contributed by Kresten Krab Thorup
This file is part of GNU CC. This file is part of GNU CC.
...@@ -30,11 +30,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -30,11 +30,7 @@ Boston, MA 02111-1307, USA. */
#include "runtime.h" #include "runtime.h"
id id
nil_method(id receiver, SEL op __attribute__ ((__unused__)), ...) nil_method (id receiver, SEL op __attribute__ ((__unused__)), ...)
{ {
return receiver; return receiver;
} }
/* Encoding of types for Objective C. /* Encoding of types for Objective C.
Copyright (C) 1993, 1997 Free Software Foundation, Inc. Copyright (C) 1993, 1997, 2002 Free Software Foundation, Inc.
Author: Kresten Krab Thorup Author: Kresten Krab Thorup
...@@ -50,30 +50,30 @@ Boston, MA 02111-1307, USA. */ ...@@ -50,30 +50,30 @@ Boston, MA 02111-1307, USA. */
#define _F_ONEWAY 0x10 #define _F_ONEWAY 0x10
#define _F_GCINVISIBLE 0x20 #define _F_GCINVISIBLE 0x20
int objc_aligned_size (const char* type); int objc_aligned_size (const char *type);
int objc_sizeof_type (const char* type); int objc_sizeof_type (const char *type);
int objc_alignof_type (const char* type); int objc_alignof_type (const char *type);
int objc_aligned_size (const char* type); int objc_aligned_size (const char *type);
int objc_promoted_size (const char* type); int objc_promoted_size (const char *type);
const char* objc_skip_type_qualifiers (const char* type); const char *objc_skip_type_qualifiers (const char *type);
const char* objc_skip_typespec (const char* type); const char *objc_skip_typespec (const char *type);
const char* objc_skip_offset (const char* type); const char *objc_skip_offset (const char *type);
const char* objc_skip_argspec (const char* type); const char *objc_skip_argspec (const char *type);
int method_get_number_of_arguments (struct objc_method*); int method_get_number_of_arguments (struct objc_method *);
int method_get_sizeof_arguments (struct objc_method*); int method_get_sizeof_arguments (struct objc_method *);
char* method_get_first_argument (struct objc_method*, char *method_get_first_argument (struct objc_method *,
arglist_t argframe, arglist_t argframe,
const char** type); const char **type);
char* method_get_next_argument (arglist_t argframe, char *method_get_next_argument (arglist_t argframe,
const char **type); const char **type);
char* method_get_nth_argument (struct objc_method* m, char *method_get_nth_argument (struct objc_method *m,
arglist_t argframe, arglist_t argframe,
int arg, int arg,
const char **type); const char **type);
unsigned objc_get_type_qualifiers (const char* type); unsigned objc_get_type_qualifiers (const char *type);
struct objc_struct_layout struct objc_struct_layout
......
...@@ -60,7 +60,7 @@ typedef struct cache_node ...@@ -60,7 +60,7 @@ typedef struct cache_node
* typedef. Therefore, to remove compiler warnings the functions passed to * typedef. Therefore, to remove compiler warnings the functions passed to
* hash_new will have to be casted to this type. * hash_new will have to be casted to this type.
*/ */
typedef unsigned int (*hash_func_type)(void *, const void *); typedef unsigned int (*hash_func_type) (void *, const void *);
/* /*
* This data type is the function that compares two hash keys and returns an * This data type is the function that compares two hash keys and returns an
...@@ -69,7 +69,7 @@ typedef unsigned int (*hash_func_type)(void *, const void *); ...@@ -69,7 +69,7 @@ typedef unsigned int (*hash_func_type)(void *, const void *);
* second. * second.
*/ */
typedef int (*compare_func_type)(const void *, const void *); typedef int (*compare_func_type) (const void *, const void *);
/* /*
...@@ -174,8 +174,8 @@ hash_string (cache_ptr cache, const void *key) ...@@ -174,8 +174,8 @@ hash_string (cache_ptr cache, const void *key)
unsigned int ctr = 0; unsigned int ctr = 0;
while (*(char*)key) { while (*(char *) key) {
ret ^= *(char*)key++ << ctr; ret ^= *(char *) key++ << ctr;
ctr = (ctr + 1) % sizeof (void *); ctr = (ctr + 1) % sizeof (void *);
} }
...@@ -187,7 +187,7 @@ hash_string (cache_ptr cache, const void *key) ...@@ -187,7 +187,7 @@ hash_string (cache_ptr cache, const void *key)
static inline int static inline int
compare_ptrs (const void *k1, const void *k2) compare_ptrs (const void *k1, const void *k2)
{ {
return !(k1 - k2); return ! (k1 - k2);
} }
...@@ -200,7 +200,7 @@ compare_strings (const void *k1, const void *k2) ...@@ -200,7 +200,7 @@ compare_strings (const void *k1, const void *k2)
else if (k1 == 0 || k2 == 0) else if (k1 == 0 || k2 == 0)
return 0; return 0;
else else
return !strcmp (k1, k2); return ! strcmp (k1, k2);
} }
......
/* Thread and mutex controls for Objective C. /* Thread and mutex controls for Objective C.
Copyright (C) 1996, 1997 Free Software Foundation, Inc. Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu) Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
This file is part of GNU CC. This file is part of GNU CC.
...@@ -74,30 +74,30 @@ struct objc_condition ...@@ -74,30 +74,30 @@ struct objc_condition
typedef struct objc_condition *objc_condition_t; typedef struct objc_condition *objc_condition_t;
/* Frontend mutex functions */ /* Frontend mutex functions */
objc_mutex_t objc_mutex_allocate(void); objc_mutex_t objc_mutex_allocate (void);
int objc_mutex_deallocate(objc_mutex_t mutex); int objc_mutex_deallocate (objc_mutex_t mutex);
int objc_mutex_lock(objc_mutex_t mutex); int objc_mutex_lock (objc_mutex_t mutex);
int objc_mutex_unlock(objc_mutex_t mutex); int objc_mutex_unlock (objc_mutex_t mutex);
int objc_mutex_trylock(objc_mutex_t mutex); int objc_mutex_trylock (objc_mutex_t mutex);
/* Frontend condition mutex functions */ /* Frontend condition mutex functions */
objc_condition_t objc_condition_allocate(void); objc_condition_t objc_condition_allocate (void);
int objc_condition_deallocate(objc_condition_t condition); int objc_condition_deallocate (objc_condition_t condition);
int objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex); int objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex);
int objc_condition_signal(objc_condition_t condition); int objc_condition_signal (objc_condition_t condition);
int objc_condition_broadcast(objc_condition_t condition); int objc_condition_broadcast (objc_condition_t condition);
/* Frontend thread functions */ /* Frontend thread functions */
objc_thread_t objc_thread_detach(SEL selector, id object, id argument); objc_thread_t objc_thread_detach (SEL selector, id object, id argument);
void objc_thread_yield(void); void objc_thread_yield (void);
int objc_thread_exit(void); int objc_thread_exit (void);
int objc_thread_set_priority(int priority); int objc_thread_set_priority (int priority);
int objc_thread_get_priority(void); int objc_thread_get_priority (void);
void * objc_thread_get_data(void); void * objc_thread_get_data (void);
int objc_thread_set_data(void *value); int objc_thread_set_data (void *value);
objc_thread_t objc_thread_id(void); objc_thread_t objc_thread_id (void);
void objc_thread_add(void); void objc_thread_add (void);
void objc_thread_remove(void); void objc_thread_remove (void);
/* /*
Use this to set the hook function that will be called when the Use this to set the hook function that will be called when the
...@@ -111,35 +111,35 @@ void objc_thread_remove(void); ...@@ -111,35 +111,35 @@ void objc_thread_remove(void);
it can be informed; for example, the GNUstep Base Library sets it it can be informed; for example, the GNUstep Base Library sets it
so it can implement the NSBecomingMultiThreaded notification. so it can implement the NSBecomingMultiThreaded notification.
*/ */
typedef void (*objc_thread_callback)(void); typedef void (*objc_thread_callback) (void);
objc_thread_callback objc_set_thread_callback(objc_thread_callback func); objc_thread_callback objc_set_thread_callback (objc_thread_callback func);
/* Backend initialization functions */ /* Backend initialization functions */
int __objc_init_thread_system(void); int __objc_init_thread_system (void);
int __objc_fini_thread_system(void); int __objc_fini_thread_system (void);
/* Backend mutex functions */ /* Backend mutex functions */
int __objc_mutex_allocate(objc_mutex_t mutex); int __objc_mutex_allocate (objc_mutex_t mutex);
int __objc_mutex_deallocate(objc_mutex_t mutex); int __objc_mutex_deallocate (objc_mutex_t mutex);
int __objc_mutex_lock(objc_mutex_t mutex); int __objc_mutex_lock (objc_mutex_t mutex);
int __objc_mutex_trylock(objc_mutex_t mutex); int __objc_mutex_trylock (objc_mutex_t mutex);
int __objc_mutex_unlock(objc_mutex_t mutex); int __objc_mutex_unlock (objc_mutex_t mutex);
/* Backend condition mutex functions */ /* Backend condition mutex functions */
int __objc_condition_allocate(objc_condition_t condition); int __objc_condition_allocate (objc_condition_t condition);
int __objc_condition_deallocate(objc_condition_t condition); int __objc_condition_deallocate (objc_condition_t condition);
int __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex); int __objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex);
int __objc_condition_broadcast(objc_condition_t condition); int __objc_condition_broadcast (objc_condition_t condition);
int __objc_condition_signal(objc_condition_t condition); int __objc_condition_signal (objc_condition_t condition);
/* Backend thread functions */ /* Backend thread functions */
objc_thread_t __objc_thread_detach(void (*func)(void *arg), void *arg); objc_thread_t __objc_thread_detach (void (*func) (void *arg), void *arg);
int __objc_thread_set_priority(int priority); int __objc_thread_set_priority (int priority);
int __objc_thread_get_priority(void); int __objc_thread_get_priority (void);
void __objc_thread_yield(void); void __objc_thread_yield (void);
int __objc_thread_exit(void); int __objc_thread_exit (void);
objc_thread_t __objc_thread_id(void); objc_thread_t __objc_thread_id (void);
int __objc_thread_set_data(void *value); int __objc_thread_set_data (void *value);
void * __objc_thread_get_data(void); void * __objc_thread_get_data (void);
#endif /* not __thread_INCLUDE_GNU */ #endif /* not __thread_INCLUDE_GNU */
...@@ -32,29 +32,29 @@ Boston, MA 02111-1307, USA. */ ...@@ -32,29 +32,29 @@ Boston, MA 02111-1307, USA. */
# include <gc.h> # include <gc.h>
#endif #endif
id __objc_object_alloc(Class); id __objc_object_alloc (Class);
id __objc_object_dispose(id); id __objc_object_dispose (id);
id __objc_object_copy(id); id __objc_object_copy (id);
id (*_objc_object_alloc)(Class) = __objc_object_alloc; /* !T:SINGLE */ id (*_objc_object_alloc) (Class) = __objc_object_alloc; /* !T:SINGLE */
id (*_objc_object_dispose)(id) = __objc_object_dispose; /* !T:SINGLE */ id (*_objc_object_dispose) (id) = __objc_object_dispose; /* !T:SINGLE */
id (*_objc_object_copy)(id) = __objc_object_copy; /* !T:SINGLE */ id (*_objc_object_copy) (id) = __objc_object_copy; /* !T:SINGLE */
id id
class_create_instance(Class class) class_create_instance (Class class)
{ {
id new = nil; id new = nil;
#if OBJC_WITH_GC #if OBJC_WITH_GC
if (CLS_ISCLASS(class)) if (CLS_ISCLASS (class))
new = (id)GC_malloc_explicitly_typed (class->instance_size, new = (id) GC_malloc_explicitly_typed (class->instance_size,
class->gc_object_type); class->gc_object_type);
#else #else
if (CLS_ISCLASS(class)) if (CLS_ISCLASS (class))
new = (*_objc_object_alloc)(class); new = (*_objc_object_alloc) (class);
#endif #endif
if (new!=nil) if (new != nil)
{ {
memset (new, 0, class->instance_size); memset (new, 0, class->instance_size);
new->class_pointer = class; new->class_pointer = class;
...@@ -63,43 +63,41 @@ class_create_instance(Class class) ...@@ -63,43 +63,41 @@ class_create_instance(Class class)
} }
id id
object_copy(id object) object_copy (id object)
{ {
if ((object!=nil)&&CLS_ISCLASS(object->class_pointer)) if ((object != nil) && CLS_ISCLASS (object->class_pointer))
return (*_objc_object_copy)(object); return (*_objc_object_copy) (object);
else else
return nil; return nil;
} }
id id
object_dispose(id object) object_dispose (id object)
{ {
if ((object!=nil)&&CLS_ISCLASS(object->class_pointer)) if ((object != nil) && CLS_ISCLASS (object->class_pointer))
{ {
if (_objc_object_dispose) if (_objc_object_dispose)
(*_objc_object_dispose)(object); (*_objc_object_dispose) (object);
else else
objc_free(object); objc_free (object);
} }
return nil; return nil;
} }
id __objc_object_alloc(Class class) id __objc_object_alloc (Class class)
{ {
return (id)objc_malloc(class->instance_size); return (id) objc_malloc (class->instance_size);
} }
id __objc_object_dispose(id object) id __objc_object_dispose (id object)
{ {
objc_free(object); objc_free (object);
return 0; return 0;
} }
id __objc_object_copy(id object) id __objc_object_copy (id object)
{ {
id copy = class_create_instance(object->class_pointer); id copy = class_create_instance (object->class_pointer);
memcpy(copy, object, object->class_pointer->instance_size); memcpy (copy, object, object->class_pointer->instance_size);
return copy; return copy;
} }
/* GNU Objective C Runtime Thread Implementation /* GNU Objective C Runtime Thread Implementation
Copyright (C) 1996, 1997 Free Software Foundation, Inc. Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
Contributed by Galen C. Hunt (gchunt@cs.rochester.edu) Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
Modified for Mach threads by Bill Bumgarner <bbum@friday.com> Modified for Mach threads by Bill Bumgarner <bbum@friday.com>
Condition functions added by Mircea Oancea <mircea@first.elcom.pub.ro> Condition functions added by Mircea Oancea <mircea@first.elcom.pub.ro>
...@@ -37,7 +37,8 @@ Boston, MA 02111-1307, USA. */ ...@@ -37,7 +37,8 @@ Boston, MA 02111-1307, USA. */
maximum priority downward only-- cannot be raised without superuser maximum priority downward only-- cannot be raised without superuser
privileges. Once lowered, it cannot be raised. privileges. Once lowered, it cannot be raised.
*/ */
static int __mach_get_max_thread_priority(cthread_t t, int *base) static int
__mach_get_max_thread_priority (cthread_t t, int *base)
{ {
thread_t threadP; thread_t threadP;
kern_return_t error; kern_return_t error;
...@@ -47,10 +48,10 @@ static int __mach_get_max_thread_priority(cthread_t t, int *base) ...@@ -47,10 +48,10 @@ static int __mach_get_max_thread_priority(cthread_t t, int *base)
if (t == NULL) if (t == NULL)
return -1; return -1;
threadP = cthread_thread(t); /* get thread underlying */ threadP = cthread_thread (t); /* get thread underlying */
error=thread_info(threadP, THREAD_SCHED_INFO, error = thread_info (threadP, THREAD_SCHED_INFO,
(thread_info_t)&info, &info_count); (thread_info_t) &info, &info_count);
if (error != KERN_SUCCESS) if (error != KERN_SUCCESS)
return -1; return -1;
...@@ -65,14 +66,14 @@ static int __mach_get_max_thread_priority(cthread_t t, int *base) ...@@ -65,14 +66,14 @@ static int __mach_get_max_thread_priority(cthread_t t, int *base)
/* Initialize the threads subsystem. */ /* Initialize the threads subsystem. */
int int
__objc_init_thread_system(void) __objc_init_thread_system (void)
{ {
return 0; return 0;
} }
/* Close the threads subsystem. */ /* Close the threads subsystem. */
int int
__objc_close_thread_system(void) __objc_close_thread_system (void)
{ {
return 0; return 0;
} }
...@@ -81,19 +82,19 @@ __objc_close_thread_system(void) ...@@ -81,19 +82,19 @@ __objc_close_thread_system(void)
/* Create a new thread of execution. */ /* Create a new thread of execution. */
objc_thread_t objc_thread_t
__objc_thread_detach(void (*func)(void *arg), void *arg) __objc_thread_detach (void (*func) (void *arg), void *arg)
{ {
objc_thread_t thread_id; objc_thread_t thread_id;
cthread_t new_thread_handle; cthread_t new_thread_handle;
/* create thread */ /* create thread */
new_thread_handle = cthread_fork((cthread_fn_t)func, arg); new_thread_handle = cthread_fork ((cthread_fn_t) func, arg);
if(new_thread_handle) if (new_thread_handle)
{ {
/* this is not terribly portable */ /* this is not terribly portable */
thread_id = *(objc_thread_t *)&new_thread_handle; thread_id = *(objc_thread_t *) &new_thread_handle;
cthread_detach(new_thread_handle); cthread_detach (new_thread_handle);
} }
else else
thread_id = NULL; thread_id = NULL;
...@@ -103,11 +104,11 @@ __objc_thread_detach(void (*func)(void *arg), void *arg) ...@@ -103,11 +104,11 @@ __objc_thread_detach(void (*func)(void *arg), void *arg)
/* Set the current thread's priority. */ /* Set the current thread's priority. */
int int
__objc_thread_set_priority(int priority) __objc_thread_set_priority (int priority)
{ {
objc_thread_t *t = objc_thread_id(); objc_thread_t *t = objc_thread_id ();
cthread_t cT = (cthread_t) t; cthread_t cT = (cthread_t) t;
int maxPriority = __mach_get_max_thread_priority(cT, NULL); int maxPriority = __mach_get_max_thread_priority (cT, NULL);
int sys_priority = 0; int sys_priority = 0;
if (maxPriority == -1) if (maxPriority == -1)
...@@ -132,7 +133,7 @@ __objc_thread_set_priority(int priority) ...@@ -132,7 +133,7 @@ __objc_thread_set_priority(int priority)
return -1; return -1;
/* Change the priority */ /* Change the priority */
if (cthread_priority(cT, sys_priority, 0) == KERN_SUCCESS) if (cthread_priority (cT, sys_priority, 0) == KERN_SUCCESS)
return 0; return 0;
else else
return -1; return -1;
...@@ -140,19 +141,19 @@ __objc_thread_set_priority(int priority) ...@@ -140,19 +141,19 @@ __objc_thread_set_priority(int priority)
/* Return the current thread's priority. */ /* Return the current thread's priority. */
int int
__objc_thread_get_priority(void) __objc_thread_get_priority (void)
{ {
objc_thread_t *t = objc_thread_id(); objc_thread_t *t = objc_thread_id ();
cthread_t cT = (cthread_t) t; /* see objc_thread_id() */ cthread_t cT = (cthread_t) t; /* see objc_thread_id () */
int basePriority; int basePriority;
int maxPriority; int maxPriority;
int sys_priority = 0; int sys_priority = 0;
int interactiveT, backgroundT, lowT; /* thresholds */ int interactiveT, backgroundT, lowT; /* thresholds */
maxPriority = __mach_get_max_thread_priority(cT, &basePriority); maxPriority = __mach_get_max_thread_priority (cT, &basePriority);
if(maxPriority == -1) if (maxPriority == -1)
return -1; return -1;
if (basePriority > ( (maxPriority * 2) / 3)) if (basePriority > ( (maxPriority * 2) / 3))
...@@ -166,17 +167,17 @@ __objc_thread_get_priority(void) ...@@ -166,17 +167,17 @@ __objc_thread_get_priority(void)
/* Yield our process time to another thread. */ /* Yield our process time to another thread. */
void void
__objc_thread_yield(void) __objc_thread_yield (void)
{ {
cthread_yield(); cthread_yield ();
} }
/* Terminate the current thread. */ /* Terminate the current thread. */
int int
__objc_thread_exit(void) __objc_thread_exit (void)
{ {
/* exit the thread */ /* exit the thread */
cthread_exit(&__objc_thread_exit_status); cthread_exit (&__objc_thread_exit_status);
/* Failed if we reached here */ /* Failed if we reached here */
return -1; return -1;
...@@ -184,42 +185,42 @@ __objc_thread_exit(void) ...@@ -184,42 +185,42 @@ __objc_thread_exit(void)
/* Returns an integer value which uniquely describes a thread. */ /* Returns an integer value which uniquely describes a thread. */
objc_thread_t objc_thread_t
__objc_thread_id(void) __objc_thread_id (void)
{ {
cthread_t self = cthread_self(); cthread_t self = cthread_self ();
return *(objc_thread_t *)&self; return *(objc_thread_t *) &self;
} }
/* Sets the thread's local storage pointer. */ /* Sets the thread's local storage pointer. */
int int
__objc_thread_set_data(void *value) __objc_thread_set_data (void *value)
{ {
cthread_set_data(cthread_self(), (any_t) value); cthread_set_data (cthread_self (), (any_t) value);
return 0; return 0;
} }
/* Returns the thread's local storage pointer. */ /* Returns the thread's local storage pointer. */
void * void *
__objc_thread_get_data(void) __objc_thread_get_data (void)
{ {
return (void *) cthread_data(cthread_self()); return (void *) cthread_data (cthread_self ());
} }
/* Backend mutex functions */ /* Backend mutex functions */
/* Allocate a mutex. */ /* Allocate a mutex. */
int int
__objc_mutex_allocate(objc_mutex_t mutex) __objc_mutex_allocate (objc_mutex_t mutex)
{ {
int err = 0; int err = 0;
mutex->backend = objc_malloc(sizeof(struct mutex)); mutex->backend = objc_malloc (sizeof (struct mutex));
err = mutex_init((mutex_t)(mutex->backend)); err = mutex_init ((mutex_t) (mutex->backend));
if (err != 0) if (err != 0)
{ {
objc_free(mutex->backend); objc_free (mutex->backend);
return -1; return -1;
} }
else else
...@@ -228,28 +229,28 @@ __objc_mutex_allocate(objc_mutex_t mutex) ...@@ -228,28 +229,28 @@ __objc_mutex_allocate(objc_mutex_t mutex)
/* Deallocate a mutex. */ /* Deallocate a mutex. */
int int
__objc_mutex_deallocate(objc_mutex_t mutex) __objc_mutex_deallocate (objc_mutex_t mutex)
{ {
mutex_clear((mutex_t)(mutex->backend)); mutex_clear ((mutex_t) (mutex->backend));
objc_free(mutex->backend); objc_free (mutex->backend);
mutex->backend = NULL; mutex->backend = NULL;
return 0; return 0;
} }
/* Grab a lock on a mutex. */ /* Grab a lock on a mutex. */
int int
__objc_mutex_lock(objc_mutex_t mutex) __objc_mutex_lock (objc_mutex_t mutex)
{ {
mutex_lock((mutex_t)(mutex->backend)); mutex_lock ((mutex_t) (mutex->backend));
return 0; return 0;
} }
/* Try to grab a lock on a mutex. */ /* Try to grab a lock on a mutex. */
int int
__objc_mutex_trylock(objc_mutex_t mutex) __objc_mutex_trylock (objc_mutex_t mutex)
{ {
if (mutex_try_lock((mutex_t)(mutex->backend)) == 0) if (mutex_try_lock ((mutex_t) (mutex->backend)) == 0)
return -1; return -1;
else else
return 0; return 0;
...@@ -257,9 +258,9 @@ __objc_mutex_trylock(objc_mutex_t mutex) ...@@ -257,9 +258,9 @@ __objc_mutex_trylock(objc_mutex_t mutex)
/* Unlock the mutex */ /* Unlock the mutex */
int int
__objc_mutex_unlock(objc_mutex_t mutex) __objc_mutex_unlock (objc_mutex_t mutex)
{ {
mutex_unlock((mutex_t)(mutex->backend)); mutex_unlock ((mutex_t) (mutex->backend));
return 0; return 0;
} }
...@@ -267,45 +268,45 @@ __objc_mutex_unlock(objc_mutex_t mutex) ...@@ -267,45 +268,45 @@ __objc_mutex_unlock(objc_mutex_t mutex)
/* Allocate a condition. */ /* Allocate a condition. */
int int
__objc_condition_allocate(objc_condition_t condition) __objc_condition_allocate (objc_condition_t condition)
{ {
condition->backend = objc_malloc(sizeof(struct condition)); condition->backend = objc_malloc (sizeof (struct condition));
condition_init((condition_t)(condition->backend)); condition_init ((condition_t) (condition->backend));
return 0; return 0;
} }
/* Deallocate a condition. */ /* Deallocate a condition. */
int int
__objc_condition_deallocate(objc_condition_t condition) __objc_condition_deallocate (objc_condition_t condition)
{ {
condition_clear((condition_t)(condition->backend)); condition_clear ((condition_t) (condition->backend));
objc_free(condition->backend); objc_free (condition->backend);
condition->backend = NULL; condition->backend = NULL;
return 0; return 0;
} }
/* Wait on the condition */ /* Wait on the condition */
int int
__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex) __objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
{ {
condition_wait((condition_t)(condition->backend), condition_wait ((condition_t) (condition->backend),
(mutex_t)(mutex->backend)); (mutex_t) (mutex->backend));
return 0; return 0;
} }
/* Wake up all threads waiting on this condition. */ /* Wake up all threads waiting on this condition. */
int int
__objc_condition_broadcast(objc_condition_t condition) __objc_condition_broadcast (objc_condition_t condition)
{ {
condition_broadcast((condition_t)(condition->backend)); condition_broadcast ((condition_t) (condition->backend));
return 0; return 0;
} }
/* Wake up one thread waiting on this condition. */ /* Wake up one thread waiting on this condition. */
int int
__objc_condition_signal(objc_condition_t condition) __objc_condition_signal (objc_condition_t condition)
{ {
condition_signal((condition_t)(condition->backend)); condition_signal ((condition_t) (condition->backend));
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment