3548 |
return result; |
return result; |
3549 |
} |
} |
3550 |
|
|
|
#define N_ELEMENTS(a) (sizeof(a) / sizeof(*(a))) |
|
|
|
|
3551 |
lt_ptr |
lt_ptr |
3552 |
lt_dlcaller_set_data (key, handle, data) |
lt_dlcaller_set_data (key, handle, data) |
3553 |
lt_dlcaller_id key; |
lt_dlcaller_id key; |
3563 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
3564 |
|
|
3565 |
if (handle->caller_data) |
if (handle->caller_data) |
3566 |
n_elements = N_ELEMENTS (handle->caller_data); |
while (handle->caller_data[n_elements].key) |
3567 |
|
++n_elements; |
3568 |
|
|
3569 |
for (i = 0; i < n_elements; ++i) |
for (i = 0; i < n_elements; ++i) |
3570 |
{ |
{ |
3576 |
} |
} |
3577 |
|
|
3578 |
/* Ensure that there is enough room in this handle's caller_data |
/* Ensure that there is enough room in this handle's caller_data |
3579 |
array to accept a new element. */ |
array to accept a new element (and an empty end marker). */ |
3580 |
if (i == n_elements) |
if (i == n_elements) |
3581 |
{ |
{ |
3582 |
lt_caller_data *temp |
lt_caller_data *temp |
3583 |
= LT_DLREALLOC (lt_caller_data, handle->caller_data, 1+ n_elements); |
= LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); |
3584 |
|
|
3585 |
if (!temp) |
if (!temp) |
3586 |
{ |
{ |
3592 |
|
|
3593 |
/* We only need this if we needed to allocate a new caller_data. */ |
/* We only need this if we needed to allocate a new caller_data. */ |
3594 |
handle->caller_data[i].key = key; |
handle->caller_data[i].key = key; |
3595 |
|
handle->caller_data[1+ i].key = 0; |
3596 |
} |
} |
3597 |
|
|
3598 |
handle->caller_data[i].data = data; |
handle->caller_data[i].data = data; |
3609 |
lt_dlhandle handle; |
lt_dlhandle handle; |
3610 |
{ |
{ |
3611 |
lt_ptr result = (lt_ptr) 0; |
lt_ptr result = (lt_ptr) 0; |
|
int n_elements = 0; |
|
3612 |
|
|
3613 |
/* This needs to be locked so that the caller data isn't updated by |
/* This needs to be locked so that the caller data isn't updated by |
3614 |
another thread part way through this function. */ |
another thread part way through this function. */ |
3615 |
LT_DLMUTEX_LOCK (); |
LT_DLMUTEX_LOCK (); |
3616 |
|
|
|
if (handle->caller_data) |
|
|
n_elements = N_ELEMENTS (handle->caller_data); |
|
|
|
|
3617 |
/* Locate the index of the element with a matching KEY. */ |
/* Locate the index of the element with a matching KEY. */ |
3618 |
{ |
{ |
3619 |
int i; |
int i; |
3620 |
for (i = 0; i < n_elements; ++i) |
for (i = 0; handle->caller_data[i].key; ++i) |
3621 |
{ |
{ |
3622 |
if (handle->caller_data[i].key == key) |
if (handle->caller_data[i].key == key) |
3623 |
{ |
{ |