1
1

but fix : unlock mutex in threaded runs for error exit.

change : lam_pointer_array_set_item() may free if null pointer passed
in.

This commit was SVN r703.
Этот коммит содержится в:
Rich Graham 2004-02-10 20:54:15 +00:00
родитель ecced268bd
Коммит 17e4854387
2 изменённых файлов: 27 добавлений и 9 удалений

Просмотреть файл

@ -8,6 +8,7 @@
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "lam/lfc/lam_pointer_array.h"
@ -52,6 +53,7 @@ size_t lam_pointer_array_add(lam_pointer_array_t *table, void *ptr)
p = malloc(TABLE_INIT * sizeof(void *));
if (p == NULL) {
THREAD_UNLOCK(&(table->lock));
return -1;
}
table->lowest_free = 0;
@ -135,10 +137,14 @@ size_t lam_pointer_array_add(lam_pointer_array_t *table, void *ptr)
* @param ptr Pointer to be added to table (IN)
*
* @return Error code
*
* Assumption: NULL element is free element.
*/
int lam_pointer_array_set_item(lam_pointer_array_t *table, size_t index,
void * value)
{
int return_value;
assert(table != NULL);
assert(table->addr != NULL);
assert(index >= 0);
@ -154,11 +160,22 @@ int lam_pointer_array_set_item(lam_pointer_array_t *table, size_t index,
THREAD_LOCK(&(table->lock));
table->addr[index] = value;
if (index < table->lowest_free) {
table->lowest_free = index;
/* reset this parameter only if in use - otherwise need to use the
* add interface funtion
*/
if( NULL != table->addr[index] ){
return_value=0;
table->addr[index] = value;
/* mark element as free, if NULL element */
if( NULL == value ) {
if (index < table->lowest_free) {
table->lowest_free = index;
}
table->number_free++;
}
} else {
return_value=1;
}
table->number_free++;
if (LAM_ENABLE_DEBUG) {
lam_output(0,"lam_pointer_array_set_item: OUT: "
@ -170,7 +187,7 @@ int lam_pointer_array_set_item(lam_pointer_array_t *table, size_t index,
THREAD_UNLOCK(&(table->lock));
return 0;
return return_value;
}
/**

Просмотреть файл

@ -2,8 +2,8 @@
* $HEADER$
*/
#ifndef _MPI_F2C_TABLE
#define _MPI_F2C_TABLE
#ifndef _LAM_POINTER_ARRAY
#define _LAM_POINTER_ARRAY
#include "lam/threads/mutex.h"
@ -19,7 +19,7 @@ typedef struct lam_pointer_array_t lam_pointer_array_t;
struct lam_pointer_array_t {
/* synchronization object */
lam_mutex_t lock;
/* index of lowest free element */
/* inde_ of lowest free element */
size_t lowest_free;
/* number of fee elements in the list */
size_t number_free;
@ -29,6 +29,7 @@ struct lam_pointer_array_t {
void **addr;
};
/**
* Add a pointer to the array (Grow the array, if need be)
*
@ -62,4 +63,4 @@ int lam_pointer_array_set_item(lam_pointer_array_t *array,
*/
void *lam_pointer_array_get_item(lam_pointer_array_t *array, size_t index);
#endif /* _MPI_F2C_TABLE */
#endif /* _LAM_POINTER_ARRAY*/