emutls.c (struct __emutls_array): New.
* emutls.c (struct __emutls_array): New. (emutls_destroy): Use it instead of casting element 0 from void*. (__emutls_get_address): Likewise. From-SVN: r123351
This commit is contained in:
parent
50decae30e
commit
5b77de89ae
|
@ -1,3 +1,9 @@
|
||||||
|
2007-03-29 Richard Henderson <rth@redhat.com>
|
||||||
|
|
||||||
|
* emutls.c (struct __emutls_array): New.
|
||||||
|
(emutls_destroy): Use it instead of casting element 0 from void*.
|
||||||
|
(__emutls_get_address): Likewise.
|
||||||
|
|
||||||
2007-03-29 Richard Henderson <rth@redhat.com>
|
2007-03-29 Richard Henderson <rth@redhat.com>
|
||||||
|
|
||||||
* varasm.c (initializer_constant_valid_p): Don't deny
|
* varasm.c (initializer_constant_valid_p): Don't deny
|
||||||
|
|
43
gcc/emutls.c
43
gcc/emutls.c
|
@ -48,6 +48,12 @@ struct __emutls_object
|
||||||
void *templ;
|
void *templ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct __emutls_array
|
||||||
|
{
|
||||||
|
pointer size;
|
||||||
|
void **data[];
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __GTHREADS
|
#ifdef __GTHREADS
|
||||||
#ifdef __GTHREAD_MUTEX_INIT
|
#ifdef __GTHREAD_MUTEX_INIT
|
||||||
static __gthread_mutex_t emutls_mutex = __GTHREAD_MUTEX_INIT;
|
static __gthread_mutex_t emutls_mutex = __GTHREAD_MUTEX_INIT;
|
||||||
|
@ -60,15 +66,16 @@ static pointer emutls_size;
|
||||||
static void
|
static void
|
||||||
emutls_destroy (void *ptr)
|
emutls_destroy (void *ptr)
|
||||||
{
|
{
|
||||||
void ***arr = (void ***) ptr;
|
struct __emutls_array *arr = ptr;
|
||||||
unsigned long int size = (unsigned long int) arr[0];
|
pointer size = arr->size;
|
||||||
++arr;
|
pointer i;
|
||||||
while (--size)
|
|
||||||
|
for (i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
if (*arr)
|
if (arr->data[i])
|
||||||
free ((*arr)[-1]);
|
free (arr->data[i][-1]);
|
||||||
++arr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free (ptr);
|
free (ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +137,9 @@ __emutls_get_address (struct __emutls_object *obj)
|
||||||
#ifndef __GTHREADS
|
#ifndef __GTHREADS
|
||||||
abort ();
|
abort ();
|
||||||
#else
|
#else
|
||||||
pointer offset;
|
pointer offset = obj->loc.offset;
|
||||||
|
|
||||||
if (__builtin_expect (obj->loc.offset == 0, 0))
|
if (__builtin_expect (offset == 0, 0))
|
||||||
{
|
{
|
||||||
static __gthread_once_t once = __GTHREAD_ONCE_INIT;
|
static __gthread_once_t once = __GTHREAD_ONCE_INIT;
|
||||||
__gthread_once (&once, emutls_init);
|
__gthread_once (&once, emutls_init);
|
||||||
|
@ -141,37 +148,37 @@ __emutls_get_address (struct __emutls_object *obj)
|
||||||
obj->loc.offset = offset;
|
obj->loc.offset = offset;
|
||||||
__gthread_mutex_unlock (&emutls_mutex);
|
__gthread_mutex_unlock (&emutls_mutex);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
offset = obj->loc.offset;
|
|
||||||
|
|
||||||
void **arr = (void **) __gthread_getspecific (emutls_key);
|
struct __emutls_array *arr = __gthread_getspecific (emutls_key);
|
||||||
if (__builtin_expect (arr == NULL, 0))
|
if (__builtin_expect (arr == NULL, 0))
|
||||||
{
|
{
|
||||||
pointer size = offset + 32;
|
pointer size = offset + 32;
|
||||||
arr = calloc (size, sizeof (void *));
|
arr = calloc (size, sizeof (void *));
|
||||||
if (arr == NULL)
|
if (arr == NULL)
|
||||||
abort ();
|
abort ();
|
||||||
arr[0] = (void *) size;
|
arr->size = size;
|
||||||
__gthread_setspecific (emutls_key, (void *) arr);
|
__gthread_setspecific (emutls_key, (void *) arr);
|
||||||
}
|
}
|
||||||
else if (__builtin_expect (offset >= (pointer) arr[0], 0))
|
else if (__builtin_expect (offset >= arr->size, 0))
|
||||||
{
|
{
|
||||||
pointer orig_size = (pointer) arr[0];
|
pointer orig_size = arr->size;
|
||||||
pointer size = orig_size * 2;
|
pointer size = orig_size * 2;
|
||||||
if (offset >= size)
|
if (offset >= size)
|
||||||
size = offset + 32;
|
size = offset + 32;
|
||||||
arr = realloc (arr, size * sizeof (void *));
|
arr = realloc (arr, size * sizeof (void *));
|
||||||
if (arr == NULL)
|
if (arr == NULL)
|
||||||
abort ();
|
abort ();
|
||||||
memset (arr + orig_size, 0, (size - orig_size) * sizeof (void *));
|
arr->size = size;
|
||||||
|
memset (arr->data + orig_size - 1, 0,
|
||||||
|
(size - orig_size) * sizeof (void *));
|
||||||
__gthread_setspecific (emutls_key, (void *) arr);
|
__gthread_setspecific (emutls_key, (void *) arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ret = arr[offset];
|
void *ret = arr->data[offset - 1];
|
||||||
if (__builtin_expect (ret == NULL, 0))
|
if (__builtin_expect (ret == NULL, 0))
|
||||||
{
|
{
|
||||||
ret = emutls_alloc (obj);
|
ret = emutls_alloc (obj);
|
||||||
arr[offset] = ret;
|
arr->data[offset - 1] = ret;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue